XNA Controls Settings

落爺英雄遲暮 提交于 2019-12-11 04:36:02

问题


I have a huge problem with editing controls for my game.. I have an ingame button and when you click it. The "Choose your key.." text appears, but I don't know how to actually set it up..

I have made a "waiting for input" bool.. THIS IS NOT THE REAL CODE IT'S HOW I IMAGINE IT TO BE

if (buttonIsClicked) waitinForInput = true;

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

Is there a way to do this.. Simpliest as I can? And sorry for my bad english.. Made this in a hurry and not my native language..

Thanks for any help.. :-)


回答1:


Something like this:

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


来源:https://stackoverflow.com/questions/15933025/xna-controls-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!