Introduction
As input is an important part of every game, it should not be difficult to use. C# provides a great feature - event handlers - which have not been used in the XNA framework to handle input. This class, CInput
, will enable event handlers for XNA.
Using the code
All you have to do to use this code is add the Input.cs file to your project, create an instance of CInput
, and call its Update
function in the game.
namespace YourGame
{
public class YourGame : Microsoft.Xna.Framework.Game
{
VisualIllusions.CInput Input;
public YourGame()
{
Input = new VisualIllusions.CInput();
Input.OnMouseDown += new
VisualIllusions.CInput.OnMouseDownDelegate(Input_OnMouseDown);
}
protected override void Update(GameTime gameTime)
{
Input.Update();
base.Update(gameTime);
}
void Input_OnMouseDown(VisualIllusions.CInput.MouseButtons b)
{
System.Diagnostics.Debug.Print("A mouse button was pressed: " +
b.ToString());
}
[...]
}
}
The class is quite simple to use, and you should be able to integrate it into your project easily by taking a look at the sample project.
Points of interest
I am currently working on GamePad
support and a binding class to make it easy to dynamically bind actions to specific keys. This binding class will be serializable so that everyone can configure his/her own set of keys.
History
- First release, and probably buggy. Let me know about any problems you notice!
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.