Hi guys, I’m learning about the accelerometer at the moment and I have noticed that in many accelerometer games (side scrollers shooter) when you tilt the device the “ship” tilts also so it looks like it’s flying up/or down.
How do I make that function for rotation when I tilt the device?
Here’s my code, I’ve tried to set player rotation in the movePlayer function but it doesn’t work, help please…
[code]
display.setStatusBar(display.HiddenStatusBar)
system.setAccelerometerInterval( 50 )
_W = display.contentWidth
_H = display.contentHeight
local bg = display.newImageRect(“images/bg.png”, 480, 320)
bg:setReferencePoint(display.CenterReferencePoint)
bg.x = _W/2
bg.y = _H/2
– My player is a fish.
local player = display.newImageRect(“images/doodle.png”, 128, 64)
player:setReferencePoint(display.CenterReferencePoint)
player.x = _W/2
player.y = _H/2
– Set up the Accelerometer values in Landscape
local motionX = 0
local motionY = 0
local function onAccelerate( event )
motionX = 10 * event.yGravity;
motionY = 10 * event.xGravity;
end
Runtime:addEventListener (“accelerometer”, onAccelerate);
– Make the player move on tilt.
local function movePlayer (event)
player.x = player.x + motionX
player.y = player.y + motionY
end
Runtime:addEventListener(“enterFrame”, movePlayer)
local function screenBoundaries (event)
– Left side boundaries
if player.x < 0 + player.width/2 then
player.x = 0 + player.width/2
end
– Right side boundaries
if player.x > display.contentWidth - player.width/2 then
player.x = display.contentWidth - player.width/2
end
– Upper boundaries
if player.y < 0 + player.height/2 then
player.y = 0 + player.height/2
end
– Lower boundaries
if player.y > display.contentHeight - player.height/2 then
player.y = display.contentHeight - player.height/2
end
end
Runtime:addEventListener(“enterFrame”, screenBoundaries)
[/code] [import]uid: 65840 topic_id: 10727 reply_id: 310727[/import]

