角色移动:如何在不移动时暂停角色。 XNA

时间:2013-11-05 16:35:34

标签: c# xna sprite sprite-sheet

当没有按下移动或操作键时,我试图阻止我的角色进行动画制作 我有一个暂停动画的功能,但我不确定如何在不完全停止角色动作的情况下实现它。

以下是我在PlayerSprite更新中所做的事情:

 this.move = (int)(GameData.PLAYER_MOVE_INCREMENT * gameTime.ElapsedGameTime.Milliseconds);
 if (SpriteManager.GAME.KEYBOARDMANAGER.isKeyDown(leftKey))
 {
     MoveBy(-move, 0);
     this.PRESENTATIONINFO.SPRITEEFFECTS = SpriteEffects.FlipHorizontally;
 }
 if (SpriteManager.GAME.KEYBOARDMANAGER.isKeyDown(rightKey))
 {
     MoveBy(move, 0);
     this.PRESENTATIONINFO.SPRITEEFFECTS = SpriteEffects.None;
 }
 if (SpriteManager.GAME.KEYBOARDMANAGER.isFirstKeyPress(Keys.Space))
 {
     bPause = !bPause;
 }

当我按下空格键时,动画会暂停,但我希望它在没有按下按键时暂停,以使角色静止不动。

提前致谢。

我通过这样做来修复它:

bPause = true;
this.move = (int)(GameData.PLAYER_MOVE_INCREMENT * gameTime.ElapsedGameTime.Milliseconds);
if (SpriteManager.GAME.KEYBOARDMANAGER.isKeyDown(leftKey))
{
    bPause = false;
    MoveBy(-move, 0);
    this.PRESENTATIONINFO.SPRITEEFFECTS = SpriteEffects.FlipHorizontally;
}
if (SpriteManager.GAME.KEYBOARDMANAGER.isKeyDown(rightKey))
{
    bPause = false;
    MoveBy(move, 0);
    this.PRESENTATIONINFO.SPRITEEFFECTS = SpriteEffects.None;
}
if (SpriteManager.GAME.KEYBOARDMANAGER.isFirstKeyPress(Keys.Space))
{
    bPause = false;
}

1 个答案:

答案 0 :(得分:0)

if (SpriteManager.GAME.KEYBOARDMANAGER.isKeyDown(leftKey))
{
   bPause = false;
   MoveBy(-move, 0);
   this.PRESENTATIONINFO.SPRITEEFFECTS = SpriteEffects.FlipHorizontally;
}
else if (SpriteManager.GAME.KEYBOARDMANAGER.isKeyDown(rightKey))
{
   bPause = false;
   MoveBy(move, 0);
   this.PRESENTATIONINFO.SPRITEEFFECTS = SpriteEffects.None;
}
else
{
   bPause = true;
}