2013-04-10 37 views
1

我有一個編輯我的遊戲控件的巨大問題..我有一個遊戲按鈕,當你點擊它。出現「選擇你的密鑰..」文本,但我不知道如何實際設置它。XNA控件設置

我做了一個「等待輸入」布爾..這不是真正的代碼它是如何想象它是

if (buttonIsClicked) waitinForInput = true; 

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

有沒有辦法做到這一點..盡我所能?很遺憾我的英文不好..提出這一着急,而不是我的母語..

感謝您的幫助.. :-)

回答

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; 
      } 
    } 
} 
+0

哇..這真的幫助..非常感謝.. :-)我不知道有可能使用類似currentKeyboardState.GetPressedKeys()[0] .. – 2013-04-11 20:49:44

+0

很高興我可以幫助! – Colton 2013-04-11 23:09:53