iphone - Rotating device while using accelerometer -
i'm using accelerometer in first cocos2d game , work fine, i'm able move sprite using below code however, when change orientation landscapeleft landscaperight, sprite stops responding y coordination, , sprite goes top of screen , doesn't respond... believe it's because of changing device orientation, i'm not sure since i'm pretty new app development, appreciated.
here sample code i'm using...
- (void)accelerometer:(uiaccelerometer *)accelerometer didaccelerate:(uiacceleration *)acceleration { //this determines how sensitive accelerometer reacts (higher = more sensitive) nsuserdefaults *defaulobj = [nsuserdefaults standarduserdefaults]; float sensitivity = [defaulobj floatforkey:@"sensitivity"]; //10.0f if (!sensitivity) { sensitivity = 6; } // controls how velocity decelerates (lower = quicker change direction) float deceleration = 0.4f; static float xval = 0; if (!self.isflag) { xval = -acceleration.x; self.isflag = true; } playervelocity.x = playervelocity.x * deceleration + (xval + acceleration.x) * sensitivity; playervelocity.y = playervelocity.y * deceleration + acceleration.y * sensitivity; playervelocity.y = playervelocity.y*-1; }
perhaps helps out, flips y along current device orientation.
float rotatedy = acceleration.y; if ([uiapplication sharedapplication].statusbarorientation==uiinterfaceorientationlandscapeleft) { rotatedy *= -1; }
then use rotatedy insteat of acceleration.y
Comments
Post a Comment