Launch sprite animation using acceleratometer.

Hi,
I’m asking myself a little question about how to launch annimation using acceleratometer.

To be clear, I would like to make my sprite running on left or on right depending of my acceleratometer value.

someone have an idea?

here is my current code (not working at the moment)

if (event.xGravity ==0) then  
 Joueur.stopAnim()  
 elseif event.xGravity \> currentXgravity then  
 Joueur.playAnim("RunLeft")  
 elseif event.xGravity \< currentXgravity then  
 patrick.playAnim("RunRight")  
 end  
  
 Joueur.mysprite.x = centerX + (centerX \* event.xGravity \*4)  
 Joueur.keepObjectIntoScene()  
  
 currentXgravity = event.xGravity  
  

Thanks you for your advise :)…

Jonathan [import]uid: 44311 topic_id: 7781 reply_id: 307781[/import]

Just tie it to current gravity, rather than the delta. Also, you need a cutoff point, as you’ll almost never get a zero reading due to the fine resolution of the accelerometer. And you’ll also need to adjust for the device orientation.

Test apps like this one may help set parameters. [import]uid: 3953 topic_id: 7781 reply_id: 27716[/import]