Accelerometer display jittery animation, not smooth

In my game there are balls falling from the sky and you try to dodge them with the white ball, as seen in the attachment. The white ball is moved by tilting the screen, and the balls go towards the direction you tilt you device. here is my code:

[lua]

local function onAccelerate( event )

    print(event.yGravity)

    player.x = player.x - (event.yGravity*10)

end

function scene:createScene( event )

group = self.view

player = display.newImageRect(“game_player.png”,67,67)

player.x = display.contentWidth - 25

player.y = ground2.y - 61

player:scale(.63,.63)

physics.addBody(player, “static”, { radius = 12 } )

player.collision = playerCollision

player:addEventListener(“collision”, player)

group:insert(player)

end

function scene:enterScene( event )

local group = self.view

Runtime:addEventListener( “accelerometer”, onAccelerate )

end

[/lua]

With the following code, whenever I tilt my device, instead of a smooth flowing motion of the ball I get a jittery, un-smooth effect where it looks like the ball is moving transporting itself forward instead of rolling. How do I change/edit my code so that the ball rolls smoothly? Thank you.

I was thinking that maybe If the code

[lua]

Runtime:addEventListener( “accelerometer”, onAccelerate )

[/lua]

Only gave the program an update on the yGravity, say every 100 milliseconds, that I could use the following code to make the animation smooth:

[lua]

function onAccelerate( event)

local playerMove = player.x + (event.yGravity)

transition.to(player, {time = 100, x = playerMove})

end

[/lua]

Would that make the animation appear to be smooth? If the Runtime event listener did only give an update every certain amount of seconds, if anyone knows what that number would be so I can implement the number into my code?

Are you calling:

system.setAccelerometerInterval( 30 )

The value should match your frame rate.  If you’re a 60fps app, set it to 60.

Rob

I put system.setAccelerometerInterval( 60 ) in my main.lua and not really changed to much, maybe it was a little smoother

Is there another way that I can fix this?

What device are you testing on?

Google Nexus 7

I would build a quick sample to test using the accelerometer to move a circle around the screen.  There is an Accelerometer sample app in SampleCode/Hardware that you can use as well.

See how that goes.

I was thinking that maybe If the code

[lua]

Runtime:addEventListener( “accelerometer”, onAccelerate )

[/lua]

Only gave the program an update on the yGravity, say every 100 milliseconds, that I could use the following code to make the animation smooth:

[lua]

function onAccelerate( event)

local playerMove = player.x + (event.yGravity)

transition.to(player, {time = 100, x = playerMove})

end

[/lua]

Would that make the animation appear to be smooth? If the Runtime event listener did only give an update every certain amount of seconds, if anyone knows what that number would be so I can implement the number into my code?

Are you calling:

system.setAccelerometerInterval( 30 )

The value should match your frame rate.  If you’re a 60fps app, set it to 60.

Rob

I put system.setAccelerometerInterval( 60 ) in my main.lua and not really changed to much, maybe it was a little smoother

Is there another way that I can fix this?

What device are you testing on?

Google Nexus 7

I would build a quick sample to test using the accelerometer to move a circle around the screen.  There is an Accelerometer sample app in SampleCode/Hardware that you can use as well.

See how that goes.