I am working on an app that is going to use the accelerometer to control the character. The code below is a stripped down version of the Sample App Accelerator 1.
My question is, how do I speed up the movement of the Circle? I've tried multiplying, adding, subtracting, but the results I've received so far are weird. Any suggestions on how to speed the Circle up?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | display.setStatusBar( display.HiddenStatusBar ) -- hide status bar -- Create a circle that moves with Accelerator events (for visual effects) -- local centerX = display.contentWidth / 2 local centerY = display.contentHeight / 2 w = display.contentWidth h = display.contentHeight print(w .. h) Circle = display.newCircle(0, 0, 20) Circle.x = centerX Circle.y = centerY Circle:setFillColor( 0, 0, 255 ) -- blue local function onAccelerate( event ) frameUpdate = false -- update done -- Move our object based on the accelerator values if(Circle.x < 1) then Circle.x = 0 elseif (Circle.x > w-3) then Circle.x = w else Circle.x = centerX + (centerX * event.xGravity) circlex.text = Circle.x .. " : " .. event.xGravity end if(Circle.y < 1) then Circle.y = 0 elseif (Circle.y > h-3) then Circle.y = h else Circle.y = centerY + (centerY * event.yGravity * -1) circley.text = Circle.y .. " : " .. event.yGravity end -- Display message and sound beep if Shake'n if event.isShake == true then -- str, location, scrTime, size, color, font media.playEventSound( soundID ) end end local function onFrame() frameUpdate = true end circlex = display.newText("X:" .. Circle.x,5,25) circley = display.newText("Y:" .. Circle.y,5,45) Runtime:addEventListener ("accelerometer", onAccelerate); Runtime:addEventListener ("enterFrame", onFrame); |
when I applied this code, I got problem that with director,
when game finish then I play again, my screen got frozen ,
how can I solve it ?
I fix my director,
and I have the same question
when I tried to change the circle.x and Y,
my object go above and down the screen, also right and left of the screen,
I think this code, does not have the speed of the object,
I am looking for the same answer ,
I think we should to speed the Frame, but how ?