我可以使用加速度计控制“小鸟”,我唯一的问题是它可以在我的设备(手机/平板电脑)平放时工作,但是当你把它拿在手上玩时它并不是空闲的。有没有办法将加速度计的零点偏移到 y 轴上的 30°(度)?
display.setStatusBar (display.HiddenStatusBar);
system.setAccelerometerInterval( 50 );
system.setIdleTimer(false);
local background = display.newImage("bg.png")
--> GAME CHARACTER
local bird = display.newImage ("helicopter.png")
bird.x = 100;
bird.y = 100;
bird:setReferencePoint(display.CenterReferencePoint);
-- Speed of Movement with tilt. You can change it ans see the effects.
local tiltSpeed = 30;
local motionx = 0;
local motiony = 0;
local rotation = 0;
local function onTilt(event)
-- Its for the new position of the bird
motionx = tiltSpeed * event.xGravity;
motiony = tiltSpeed * event.yGravity;
end
local function moveBird (event)
bird.x = motionx + bird.x;
bird.y = bird.y - motiony;
bird.rotation = rotation;
end
Runtime:addEventListener("accelerometer", onTilt)
Runtime:addEventListener("enterFrame", moveBird)