Xna not getting imput from keyboard on new projects
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]
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.
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.
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();
}
}
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();
}
}
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(); }}
have you looked at the samples on the creators.xna site? All of them have been updated to xna 2.0, and all of them use input
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement