-1
你好,我在XNA一些麻煩,在這裏我的代碼 我做一個陣列的4KeyboardState在XNA C#
//Initialize
Keyboard oldState = Keyboard.GetState();
int index = 0;
//Update
KeyboardState currentState = Keyboard.GetState();
if (index != 0 && ((currentState.IsKeyDown(Keys.Z) || currentState.IsKeyDown(Keys.Up))
&& ((!oldState.IsKeyDown(Keys.Z)) || (!oldState.IsKeyDown(Keys.Up)))))
{
index = index - 1;
}
else if (index < menuArray.Length && ((currentState.IsKeyDown(Keys.S) || currentState.IsKeyDown(Keys.Down))
&& ((!oldState.IsKeyDown(Keys.S)) || (!oldState.IsKeyDown(Keys.Down)))))
{
index = index + 1;
}
oldState = currentState;
if (index == 0)
//put the texture here
if (index == 1)
//put the texture here
if (index == 2)
// put the texture here
if (index == 3)
// put the texture here
我的主要問題是,當我按上/ Z或向下/ S的長度,如果我沒有按下光標,光標將從3跳到3或從0跳到0 您能幫我解決這個問題嗎?
您正在過度使用oldstate變量。所以這兩個變量總是相等的。此外,您需要記住這部分代碼每次調用時都會運行,通常約爲60 fps。 – deathismyfriend