Jump to content
  • Advertisement
Sign in to follow this  
mysockshurt

Xna not getting imput from keyboard on new projects

This topic is 3816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

A week ago I did a moving sprite project in xna and the sprite currently moves. The problem is when I added KeyboardState keyboard = Keyboard.GetState(); // Back or Escape exits our game on Xbox 360 and Windows if (gamePad.Buttons.Back == ButtonState.Pressed || keyboard.IsKeyDown(Keys.Escape)) this.Exit(); and it doesn't escape the project. It works on all older projects done a week ago but not on newer ones or ones I have changed. Also now when I add input to it(the same style as a week ago) it is not recognized the sprite still stays where it was when it loaded. Any suggestions? Any were else to ask? Has the happened to you? Pre made projects work with escape(Ones from xna creators, but still its not getting input. Thanks [Edited by - mysockshurt on January 12, 2008 10:05:46 AM]

Share this post


Link to post
Share on other sites
Advertisement
The top was edited because of a couple mistakes

Also I am getting strange errors if KeyboardState keyboard = Keyboard.GetState(); is not on one line. It says the errors is the = and () sign?
Any other suggestions? This happens with both xna refresh and 2.0 projects. Also some classes are not recognized in the main game class. I had to restart the application to have it recognized by intelesense, this happened a couple times. Is there any other fix for this.

Share this post


Link to post
Share on other sites
I am checking input in the update method and made a separate function to check keys and it checks for space bar and escape . It worked the first time and the second time it didn't(for the space bar). Also I tried this method on a different project and it didn't exit. This seems very odd.

the method code is(i tried both protected and public)And then its put into update(The regular one Microsoft has also doesn't exit.


protected void checkkeys()
{
if (keyboard.IsKeyDown(Keys.Escape))
{
this.Exit();
}
}

Share this post


Link to post
Share on other sites
Quote:
Original post by mysockshurt
I am checking input in the update method and made a separate function to check keys and it checks for space bar and escape . It worked the first time and the second time it didn't(for the space bar). Also I tried this method on a different project and it didn't exit. This seems very odd.

the method code is(i tried both protected and public)And then its put into update(The regular one Microsoft has also doesn't exit.


protected void checkkeys()
{
if (keyboard.IsKeyDown(Keys.Escape))
{
this.Exit();
}
}


Make sure you are calling the GetState method of the keyboard object each time you check for input. Try change your checkkeys method to:


protected void CheckKeys()
{
KeyboardState ks = Keyboard.GetState();

if(ks.IsKeyDown(Keys.Escape))
{
this.Exit();
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!