好吧,我在XNA,Visual C#2010 Express Edition中創建了一個遊戲。我有一個可以成功完成運行週期的簡筆圖,所以我希望添加一個「避讓」功能。如果你保持輪班,你可以鴨子 - 哪個工作。但是隨後我在動畫中添加了一個額外的圖層,並在代碼中聲明瞭shift和A是否被按下或shift和D,然後底部行上的動畫會循環。它只會到下一幀,然後從那裏移動,正如我在標題中所述,這很可能是程序無法同時檢測兩個按鍵的結果。這是我的代碼的摘錄,任何幫助將不勝感激。XNA中的多鍵按鍵
else if (keyboardstate.IsKeyDown(Keys.LeftShift))
{
currentFrame.X = 0;
currentFrame.Y = 8;
}
if (keyboardstate.IsKeyDown(Keys.LeftShift) && keyboardstate.IsKeyDown(Keys.A) && killed == false)
{
pos.X -= speed;
this.flip = SpriteEffects.FlipHorizontally;
leftPress = true;
timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
if (timeSinceLastFrame > millisecondsPerFrame)
{
timeSinceLastFrame -= millisecondsPerFrame;
++currentFrame.X;
if (currentFrame.X >= 8)
{
currentFrame.X = 0;
}
}
}
if (keyboardstate.IsKeyDown(Keys.LeftShift) && keyboardstate.IsKeyDown(Keys.D) && killed == false)
{
pos.X += speed;
if (leftPress == true)
{
this.flip = SpriteEffects.None;
}
timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
if (timeSinceLastFrame > millisecondsPerFrame)
{
timeSinceLastFrame -= millisecondsPerFrame;
++currentFrame.X;
if (currentFrame.X >= 8)
{
currentFrame.X = 0;
}
}
}
else if (keyPress.IsKeyUp(Keys.LeftShift) && keyRelease.IsKeyDown(Keys.LeftShift) && killed == false)
{
currentFrame.X = 0;
currentFrame.Y = 0;
leftPress = false;
}
P.S.這裏是我的spritesheet供參考。 :) http://oi43.tinypic.com/2v1uohg.jpg
P.S.S.這裏的所有內容都位於Update方法中。