1

我在为我的游戏编辑控件时遇到了一个大问题。我有一个游戏内按钮,当你点击它时。出现“选择您的密钥..”文本,但我不知道如何实际设置它..

我做了一个“等待输入”bool..这不是真正的代码它是我想象的那样

if (buttonIsClicked) waitinForInput = true;

while(waitingForInput)
{
kbState = Keyboard.GetState();
somehow convert it to Keys.(STH);
if (Keys.STH != defaultKeys)
{
defaultKeys = Keys.STH;
waitingForInput = false;
}
}

有没有办法做到这一点.. 尽可能简单?对不起我的英语不好..这是匆忙而不是我的母语..

谢谢你的帮助.. :-)

4

1 回答 1

0

像这样的东西:

 KeyboardState currentKeyboardState = new KeyBoardState();
 KeyboardState previousKeyboardState = new KeyBoardState();

 Keys jumpKey = Keys.Space;

 public void handleInput()
 {
     lastKeyboardState = currentKeyboardState;

     currentKeyboardState = Keyboard.GetState(PlayerIndex.One);

     bool waitingForKey = false;

     if(currentKeyboardState.IsKeyDown(Keys.A) && waitingForKey == false)
     {
         waitingForKey = true;            
     }

     if(waitingForKey == true)
     {
          //currentKeyboardState.GetPressedKeys() returns a list of pressed keys,
          //So, currentKeyboardState.GetPressedKeys()[0] returns the first pressed key

          if(currentKeyboardState.GetPressedKeys().Count() > 0)
          {
            jumpKey = currentKeyboardState.GetPressedKeys()[0];
            waitingForKey = false;
          }
     }
 }
于 2013-04-10T20:26:01.380 回答