-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