Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Accelerometer display jittery animation, not smooth
Started by ytduglepvp Oct 19 2014 11:11 AM

7 replies to this topic
accelerometer
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ytduglepvp

[GLOBAL: userInfoPane.html]
ytduglepvp
  • Enthusiast

  • 38 posts
  • Corona SDK

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:

 

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



 

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.

Attached Files



[TOPIC: post.html]
#2

ytduglepvp

[GLOBAL: userInfoPane.html]
ytduglepvp
  • Enthusiast

  • 38 posts
  • Corona SDK

I was thinking that maybe If the code

Runtime:addEventListener( "accelerometer", onAccelerate )

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:

 

 
function onAccelerate( event)
 
local playerMove = player.x + (event.yGravity)
 
transition.to(player, {time = 100, x = playerMove})
 
end

 

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?



[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,646 posts
  • Enterprise

Are you calling:

 

system.setAccelerometerInterval( 30 )

 

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

 

Rob



[TOPIC: post.html]
#4

ytduglepvp

[GLOBAL: userInfoPane.html]
ytduglepvp
  • Enthusiast

  • 38 posts
  • Corona SDK

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



[TOPIC: post.html]
#5

ytduglepvp

[GLOBAL: userInfoPane.html]
ytduglepvp
  • Enthusiast

  • 38 posts
  • Corona SDK

Is there another way that I can fix this?



[TOPIC: post.html]
#6

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,646 posts
  • Enterprise

What device are you testing on?



[TOPIC: post.html]
#7

ytduglepvp

[GLOBAL: userInfoPane.html]
ytduglepvp
  • Enthusiast

  • 38 posts
  • Corona SDK

Google Nexus 7



[TOPIC: post.html]
#8

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,646 posts
  • Enterprise

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.




[topic_controls]
[/topic_controls]