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]