0

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

这是我在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;
}
4

1 回答 1

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;
}
于 2013-11-05T17:44:33.757 回答