How to calibrate the accelerometer for my iPhone game? Currently, when the phone is on a flat surface, the paddle drifts to the left. High or low pass filters are not an acceptable solution, as I need full control of the paddle even at low and high values. I know that Apple has a sample of BubbleLevel, but it's hard for me to follow ... can someone simplify the process?
My accelerometer code looks like this:
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { float acelx = -acceleration.y; float x = acelx*40; Board *board = [Board sharedBoard]; AtlasSprite *paddle = (AtlasSprite *)[board.spriteManager getChildByTag:10]; if ( paddle.position.x > 0 && paddle.position.x < 480) { paddle.position = ccp(paddle.position.x+x, paddle.position.y); } if ( paddle.position.x < 55 ) { paddle.position = ccp(56, paddle.position.y); } if ( paddle.position.x > 435 ) { paddle.position = ccp(434, paddle.position.y); } if ( paddle.position.x < 55 && x > 1 ) { paddle.position = ccp(paddle.position.x+x, paddle.position.y); } if ( paddle.position.x > 435 && x < 0) { paddle.position = ccp(paddle.position.x+x, paddle.position.y); } }
Thanks!
iphone accelerometer calibration
user2393462435
source share