Hey guys, I just finished my app with Corona SDK and thought I'd try to make my first game.
As my first app was learning about the accelerometer I thought my game should be with that too.
So I placed a little doodle on the screen and got him controlled by the accelerometer in both X and Y direction, the game is in landscape but if I have the device on an angle towards me the doodle slides off the screen in Y direction.
If I would be laying in bed or slouching on the couch then the game won't be playable.
How do I write a function that compensate this angle?
Here is the code I have for the accelerometer at the moment;
display.setStatusBar(display.HiddenStatusBar)
system.setAccelerometerInterval( 50 )
_W = display.contentWidth
_H = display.contentHeight
local player = display.newImageRect("doodle.png", 64, 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))