当没有按下移动或操作键时,我试图阻止我的角色进行动画制作 我有一个暂停动画的功能,但我不确定如何在不完全停止角色动作的情况下实现它。
以下是我在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;
}
答案 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;
}