我的工作在遊戲中,我想在加速度計tilt.i都提到這個教程http://www.raywenderlich.com/457/intro-to-box2d-with-cocos2d-tutorial-bouncing-balls的方向移動CCSprite,但我不說清楚。請任何人都可以幫助我。如何在景觀iPhone/iPad的使用加速度計
在此先感謝。
我的工作在遊戲中,我想在加速度計tilt.i都提到這個教程http://www.raywenderlich.com/457/intro-to-box2d-with-cocos2d-tutorial-bouncing-balls的方向移動CCSprite,但我不說清楚。請任何人都可以幫助我。如何在景觀iPhone/iPad的使用加速度計
在此先感謝。
請參閱要http://bobueland.com/那裏你可以找到加速計示例教程
請參閱此解決方案。在風景遊戲中,我使用從左到右移動精靈的相同方式。:See answer here
只有橫向模式的更改是使用加速度計y代替x。
-(void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
if(self.isGamePaused || self.isGameOver)
return;
float deceleration = 1.0f, sensitivity = 15.0f, maxVelocity = 450;
if(sGame.IsIpad)
{
sensitivity = 14.0f;
maxVelocity = 850;
deceleration = 1.5f;
}
// adjust velocity based on current accelerometer acceleration
// vel.x = vel.x * deceleration + acceleration.x * sensitivity;
AppController *app = (AppController*)[UIApplication sharedApplication].delegate;
float velocity_x = self.gameActor.velocity.x ;
self.gameActor.accelVal = ABS(acceleration.y);
if(app.orient == UIInterfaceOrientationLandscapeLeft)
{
velocity_x = velocity_x * deceleration + acceleration.y * sensitivity;
}
else
{
velocity_x = velocity_x * deceleration + (-acceleration.y) * sensitivity;
}
//limit the maximum velocity of the player sprite, in both directions (positive & negative values)
velocity_x = fmaxf(fminf(velocity_x, maxVelocity), -maxVelocity);
self.gameActor.velocity = ccp(velocity_x, self.gameActor.velocity.y);
}