开发者

Accelerometer direction detection

I have the following code

playerPosition.x += acceleration.x * 10;
playerPosition.y += acceleration.y * 20;

acceleration currently works, I wou开发者_C百科ld like to detect if the player should move backwards(y decreasing) and if so change it to

playerPosition.y += acceleration.y * 10;

How does one detect if acceleration from the accelerometer is negative?

How does one retrieve the direction of the movement? left right etc?


You just compare the acceleration with 0

acceleration.y < 0.0

or

acceleration.y > 0.0

There is a free app iSimulate where you can see what values accelerometer outputs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜