Thursday, November 17, 2011

Embedding XNA Content in Compiled Code


I recently discovered that you can use the Content Pipeline in conjunction with a resource (as in .resx). This is very useful for embedding resources in a .dll if you need to ship your library with textures or models.

Compile any content you want with this project and add the resulting .xnb to your .resx.

Then create an instance of the ResourceContentManager class and load the content in the same way as you are accustom to doing with a content project.

Tuesday, November 15, 2011

Event driven input for XNA on the PC

XNA Input limitations:

XNA has a rather severe limitation with regards to handling keyboard input. It is unable detect any keystrokes that occur between pollings. Because of this if your game is updating at the default 60 fps there are 0.017 seconds between polls can be to slow for individual characters of memorized sequences such as "ing".

To solve this leidegren.se created a hook that is very easy to incorporate into your project. This post is to help you get set up and serve as a reference should you need it. Feel free to post any quirks you run into and I'll add them.

Here is how to set it up:

To initialize the hook.


After initializing the hook there are 9 events that it will trigger. The names are very self explanatory so I'm only gong to talk about a few of the quirks I have come across.


CharEntered returns everything that is a character including returns, backspace  characters, and the like. Also keyborad combinations such as Ctrl + C are represented as a single character which can be compared by casing the integer value of the character (for example Ctrl + x == (char)3). CharEntered repeats if the corresponding key is healed down, a behavior very useful for text boxes and the like.

Different types of delegates