0

C#でコーディングし、XNA 4.0フレームワークを使用して、プレーヤーの制御に関して、キーボードとゲームコントローラーの両方の入力用に開発しようとしています。

ゲームコントローラー入力のコードは次のとおりです。

GamePadState gamepadState = GamePad.GetState(PlayerIndex.One); 

if(gamepadState.ThumbSticks.Left.X != 0 || gamepadState.ThumbSticks.Left.Y != 0) 
{   
     //Handles rotation
     angle += thumbsticksMove(gamepadState); //handles Left.X and Left.Y input
     normalize(); //normalizes angle and sets normalizedAngle = angle
     this.Rotate(normalizedAngle); //takes value and passes it through Math helper
     //atan and pi*2
     //Ends handles rotation

     pos += (angle * speed);

     //Implementing framerate adjustment just for this class
     timeSinceLastFrame += (float)gameTime.ElapsedGameTime.Milliseconds;
     if (timeSinceLastFrame > millisecondsPerFrame)
     {
          timeSinceLastFrame -= millisecondsPerFrame;
          Animation();
     }
}

これにより、プレーヤーが期待どおりに移動し、スプライトが適切な方向に反転しますが、アニメーションピースは機能しませ。スプライトは、入力時にプレーヤーの動きでアニメーション化することになっています。これは、キーボードからの入力を取り込むときにうまく機能します。以下を参照してください。

if (Keyboard.GetState().IsKeyDown(Keys.Right))
{
       input = Vector2.Zero;
       input.X = 1;

       //Handles rotation
       angle.X = input.X;
       normalize();
       this.Rotate(normalizedAngle);
       //Ends handles rotation

       pos += (input * speed);
       //Implementing framerate adjustment just for this class
       timeSinceLastFrame += (float)gameTime.ElapsedGameTime.Milliseconds;
       if (timeSinceLastFrame > millisecondsPerFrame)
       {
       timeSinceLastFrame -= millisecondsPerFrame;
       Animation();
       }
}

キーボード入力では機能するが、ゲームコントローラー入力では機能しない理由を理解するのに苦労しています。アニメーション化しようとしているように見えますが、3番目のアニメーションセルを完全に通過したり、ほとんどアニメーション化されていないように見えるほど速くアニメーション化することはありません。どんな助けでも大歓迎です!

4

1 に答える 1

0

結局追加しました

if (gamepadState.IsConnected){//Gamepad code}

if (!gamepadState.IsConnected){//Keyboard code}

入力を個別に読み取ると、問題が解決したようです。

みんなの助けに感謝します。

于 2013-01-30T02:11:08.247 に答える