XNA GPA Blog
December 19, 2009Sorry I've Been Busy
If you have been following my blog on the role playing game tutorials you will
know that I've been having a few problems of late. I got a new computer and I
now have all of the programs I need to work on these tutorials installed. Since
making the move to Windows 7 I've had a small issue with the map editor. I did
manage to get it fixed though. I had to start it over again, I won't go into
fixing it in a tutorial. Instead, I'm going to remove it from Eyes of the Dragon
and make it available for download.
I will be working on more XNA tutorials in the near future. I will be going out of town from December 22nd, 2009 to December 27th, 2009. I hope that when I get back.
I will be working on more XNA tutorials in the near future. I will be going out of town from December 22nd, 2009 to December 27th, 2009. I hope that when I get back.
December 10, 2009
Picking Up Items
For Eyes of the Dragon, the game for my tutorial series on creating a
role playing game with XNA, I'm working on having the player to be able
to pick up items off the map. I will also be working on some classes that
have to do with the player's inventory and items.
December 9, 2009
Moving Through Sprites
What I am working on for the next tutorial on creating a role playing
game with XNA is that at the moment the player can walk through the NPCS
in the game. This isn't really a good thing so I've decided to finally
fix this. I hope to have the tutorial on this available on my web site
for download today.
December 7, 2009
Screen Manager
I am working on a short tutorial on creating and using a screen manager
with XNA. As games get larger and larger it is a good idea to separate
the game into classes and have a manager to manage the different screens
or states in your game. I'm writing a two part series on creating a screen
management system with XNA game components. XNA game components work like
mini-games in that they have all the methods of an XNA game, only Drawable
Game Components have Draw methods though. I have the first part finished and
I hope to have the second written and both up on the site in the very near
future, possibly even tomorrow.
December 5, 2009
Visual elements
What I am working on at the moment is adding sprites for the different
characters. Since there are four classes and two genders there will be
eight sprites in total. What I would like to do is have a different sprite
for each of the classes and genders. In the character generator when the
player is selecting creating their character a picture of the appropriate
sprite will be on the screen as well. While a minor thing it has been
bugging me for a while.
December 4, 2009
Introducing XNA GPA Blog
I would like to welcome you to my XNA tutorials blog. On this blog I will be
writing about what I am working on in my tutorials and I will also be writing
short little tutorials about using XNA and accomplishing many different tasks
using XNA. The first one that I am going to add is a quick little tutorial on
how to detect single key presses.
Many XNA programmers check for a single press using the keyboard by checking to see if the current state of the key they are checking is down and the last state of the object is up. This is actually not a very good way to go about this and I will explain why. The reason is if you are using this for a menu and it goes to a second menu the menu may still have the same values for the new and old state of the keyboard. A much better way is to check to see if the current state of the key you are checking is up and the last state of the keyboard is down. What that will do is check to see if a key has been pressed and released and stop the last key press from moving to the next frame.
Now I will give you a little snippet of code that you can use in your games to check to see if a key has been pressed and release using XNA. To use this snippet you need to have two fields in your class to hold the current state of the keyboard and the last state of the keyboard. At the start of the Update method you get the current state of the keyboard and at the end of the Update method you set the old state of the keyboard to be the new state of the keyboard. I wrote a little method that you can add to your game that will return true if the key has been pressed and released and false otherwise.
Many XNA programmers check for a single press using the keyboard by checking to see if the current state of the key they are checking is down and the last state of the object is up. This is actually not a very good way to go about this and I will explain why. The reason is if you are using this for a menu and it goes to a second menu the menu may still have the same values for the new and old state of the keyboard. A much better way is to check to see if the current state of the key you are checking is up and the last state of the keyboard is down. What that will do is check to see if a key has been pressed and released and stop the last key press from moving to the next frame.
Now I will give you a little snippet of code that you can use in your games to check to see if a key has been pressed and release using XNA. To use this snippet you need to have two fields in your class to hold the current state of the keyboard and the last state of the keyboard. At the start of the Update method you get the current state of the keyboard and at the end of the Update method you set the old state of the keyboard to be the new state of the keyboard. I wrote a little method that you can add to your game that will return true if the key has been pressed and released and false otherwise.
KeyboardState newState;
KeyboardState oldState;
protected override void Update(GameTime gameTime)
{
newState = Keyboard.GetState();
if (CheckKey(Keys.Space) == true)
{
// space bar has been pressed once!
}
base.Update(gameTime);
oldState = newState;
}
private bool CheckKey(Keys theKey)
{
return oldState.IsKeyDown(theKey) && newState.IsKeyUp(theKey);
}
KeyboardState oldState;
protected override void Update(GameTime gameTime)
{
newState = Keyboard.GetState();
if (CheckKey(Keys.Space) == true)
{
// space bar has been pressed once!
}
base.Update(gameTime);
oldState = newState;
}
private bool CheckKey(Keys theKey)
{
return oldState.IsKeyDown(theKey) && newState.IsKeyUp(theKey);
}
Good luck with your XNA game programming adventures.
Jamie McMahon
