CCSprite を加速度計の傾きの方向に動かしたいゲームに取り組んでいます。しかし、私はそれについて明確ではありません。誰でも私を助けてください。
前もって感謝します。
CCSprite を加速度計の傾きの方向に動かしたいゲームに取り組んでいます。しかし、私はそれについて明確ではありません。誰でも私を助けてください。
前もって感謝します。
この解決策を参照してください。ランドスケープゲームでスプライトを左から右に移動するために同じものを使用しました。 :こちらの回答を参照してください
ランドスケープ モードの唯一の変更点は、x の代わりに加速度計 y を使用することです。
-(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);
}