I have a simple logic for my 2d game that is enabled on the iphone with the orientation locked to Landscape Left.
If the phone is rotate away from you, imagine holding it in landscape mode, I want my object to be moved up otherwise I want the object to be moved down.
-(void)outputRotationData:(CMRotationRate)rotation
{
if (fabs(currentMaxRotY - rotation.y) < .3) {
return;
}
if(rotation.y > 0 ){
if (!(ship.position.y < 10)) {
[ship runAction:actionMoveDown];
NSLog(@"moving down");
}
}else{
if (!(ship.position.y > screenHeight)) {
[ship runAction:actionMoveUp];
NSLog(@"moving up");
}
}
currentMaxRotY = rotation.y;
}
The code above works. Just not as you would expect. Even when the phone is rotated away from you, sometimes the object moves down; however it correctly moves up most of the times. I assume due to the sensitivity which I thought would have been fixed by returning if our last rotation and current rotation don't differ by more than .3