accelerometer help

I am making a simple game where a character runs left or right. I had it set up with arrows but on device I want
to use accelerometer controls, but have never done it before. I have my code set up for sprite to play left animation with left arrow
and run right animation with right arrow. (see below)

what must I do code wise to have this happen on device but run left/right with accelerometer?
[lua]local function stop (event)
if event.phase ==“ended” then
motionx = 0
guy:play(“idle”)
end
end
Runtime:addEventListener(“touch”, stop )

– Move character
local function moveguy (event)
guy.x = guy.x + motionx;
end
Runtime:addEventListener(“enterFrame”, moveguy)

local function wrapit (event)
if guy.x > 430 then
guy.x = 430
end
if guy.x < 0 then
guy.x = 0
end
end
Runtime:addEventListener(“enterFrame”, wrapit)

– When left arrow is touched, move character left
function left:touch()
motionx = -speed;
guy:play(“walk_left”)

end
left:addEventListener(“touch”,left)

– When right arrow is touched, move character right
function right:touch()
motionx = speed
guy:play(“walk_right”)
end
right:addEventListener(“touch”,right)[/lua] [import]uid: 58922 topic_id: 33976 reply_id: 333976[/import]

I’ve read the corona api’s, the forums, tut sites…none of that addresses what I need.
I am using a module for my “sprites” which is basically a modified dealie for movieclip,

when the device is tilted left, i need to:

guy:play(“walk_left”)
if device is titled right I need to:
guy:play(“walk_right”)

and if still I need it to:

guy:play(“idle”)

nowhere online does it explain how to accomplish this.
I need someone to please address this asap, client depends on it [import]uid: 58922 topic_id: 33976 reply_id: 135222[/import]

What have you tried so far ?

get accelerometer working
http://developer.coronalabs.com/content/accelerometer-1

Add xGravity to motionx, use yGravity if in landscape mode

Make one function to move your player

  • create a var outside that function for lastx
  • test if player.x > player.x + motionx
  • if it is and ‘walk-right’ is not the current sequence, then start ‘walk-right’
  • use same approach for ‘walk-left’

-add or subtract, depending on orientation, motionx to player

  • make player.x an integer using ceil or floor, example local tempx = math.ceil(player.x)
    -compare it to lastx
  • if tempx is the same as lastx and ‘idle’ is not playing, then start ‘idle’
  • update lastx = tempx [import]uid: 186251 topic_id: 33976 reply_id: 135252[/import]

I’ve read the corona api’s, the forums, tut sites…none of that addresses what I need.
I am using a module for my “sprites” which is basically a modified dealie for movieclip,

when the device is tilted left, i need to:

guy:play(“walk_left”)
if device is titled right I need to:
guy:play(“walk_right”)

and if still I need it to:

guy:play(“idle”)

nowhere online does it explain how to accomplish this.
I need someone to please address this asap, client depends on it [import]uid: 58922 topic_id: 33976 reply_id: 135222[/import]

What have you tried so far ?

get accelerometer working
http://developer.coronalabs.com/content/accelerometer-1

Add xGravity to motionx, use yGravity if in landscape mode

Make one function to move your player

  • create a var outside that function for lastx
  • test if player.x > player.x + motionx
  • if it is and ‘walk-right’ is not the current sequence, then start ‘walk-right’
  • use same approach for ‘walk-left’

-add or subtract, depending on orientation, motionx to player

  • make player.x an integer using ceil or floor, example local tempx = math.ceil(player.x)
    -compare it to lastx
  • if tempx is the same as lastx and ‘idle’ is not playing, then start ‘idle’
  • update lastx = tempx [import]uid: 186251 topic_id: 33976 reply_id: 135252[/import]