I created a C# class that allows you to use more than one mouse in your XNA game. Of course this is also working with normal Windows applications, but I specially prepared it to work with XNA. This gives you new possibilities for multiplayer games on a single computer! Currently, it’s only working for mice, but I will add keyboard support soon.
Download MultiInput.dll Version 0.1
I also created a game demonstrating how to use this class and what multiple mice can be used for. I think there are many games that could make use of more than one mouse to enable a cool multiplayer mode. Currently the game is in Alpha stage and doesn’t have many features. It supports up to 6 players (if that many mice are plugged in) who have to stop zeppelins from reaching the other side of the screen by shooting them down. Although there isn’t much to do except shooting the zeppelins, it’s quite funny already.
UPDATE: NEW VERSION AVAILABLE: Download Airship Assault here!
Download MultiInput Sample Game Alpha Version 0.1
Download and install the necessary XNA Framework 3.0 here
Each crosshair can be controlled by one mouse/player. The number in brackets on the bottom is the amout of shots you’ve left in your magazine. Leftclick to shoot, rightclick to reload. When a zeppelin reaches the other side, you will lose a life.
I tested the game only with USB mice, they’re working fine, but it should also work with PS2 mice. If you encounter any errors, please tell me!
Using MultiInput.dll
The usage of this class is really easy. Copy the DLL file to your project’s folder and set a reference to the DLL and a reference to the “System.Windows.Forms” namespace (don’t forget this!). Load the dll using
Inside your Game class, you can use the code like this:
class Game1 { MultiInputController inputController; Color[] mousecolors = new Color[] { Color.Red, Color.Blue, Color.Green, Color.Yellow, Color.White, Color.Pink }; public Game1() { inputController = new MultiInputController(this.Window.Handle); } public override void UnloadContent() { // YOU MUST!!! USE THIS LINE, otherwise your game won't exit inputController.Dispose(); content.Unload(); } public override void Update(GameTime gameTime) { foreach(RawMouse rawmouse in inputController.Mice) { // do whatever you like here } base.Update(gameTime); } public override void Draw(GameTime gameTime) { spriteBatch.Begin(); // Draw each cursor for (int i = 0; i < inputController.MiceCount; i++) { RawMouse mouse = inputController.Mice[i]; spriteBatch.Draw(cursor, new Vector2((float)(mouse.X - cursor.Width/2), (float)(mouse.Y - cursor.Height/2)), mousecolors[i]); } spriteBatch.End(); } }

March 23rd, 2009 at 1:29 pm
Very nice…It won’t work with my touch screen/stylus though. And the sensitivity is either off or its lagging.
March 23rd, 2009 at 1:51 pm
hmm, if windows recognized your touch screen as a normal mouse, it should work. otherwise the game wont detect it.
and the stuff with teh lagging.. many people told me taht, its actually not lagging, the game runs completely fluid, it just sometimes ignores your clicking. on my comp with my mice it happens in like 2% of all clicks, thats why i ignored it, but at your computers it must be worse. i will try to fix it somehow.
and i created a far better version of the game, will upload it soon!
March 26th, 2009 at 12:39 am
[...] Assault is the first game that uses my MultiInput library in order to support many players playing the same game on one computer with multiple mice connected [...]
July 17th, 2009 at 4:52 am
Excelente work! I really needed to know if XNA supported multiple mice functionallity to choose it as our development platform and you just solve our doubts, thanks!
ps: A little recommendation: there are better sites for uploading files than rapidshare or megaupload (both which I personally hate). I use one which i found specially good: http://drop.io/
July 20th, 2009 at 4:18 pm
thanks for your comment! i know there are better sites, and dont like rapidshare as well (the waiting time, only one download at a time, ip blocking,…) but megaupload is ok i think.
March 1st, 2010 at 4:17 am
Error 1 The name ‘cursor’ does not exist in the current context
Error 1 The name ‘lt’ does not exist in the current context
for (int i = 0; i < inputController.MiceCount; i++)
I want to integrate your library to use two mice in a 3d game I’m making but I don’t understand how to use it, can you please elaborate more on how to use it and can you please explain how to fix these errors?
March 1st, 2010 at 4:18 am
for (int i = 0; i < inputController.MiceCount; i++)
Error 1 The name ‘lt’ does not exist in the current context
March 1st, 2010 at 3:48 pm
Oh, did you just copy the code above? There is a bug, it says “for (int i = 0; i < inputController.MiceCount; i++)”, where the < should be < , but my blog changes it for security reasons. Replace it in your code and it should work
March 1st, 2010 at 3:49 pm
Okay well, it does the same when commenting and just switches & lt ; (without the spaces) back to < . At least now you can see how it should look like, in my comment above.
Leave a Reply
© 2009 by Lennart Moltrecht | Site Admin | Entries (RSS) and Comments (RSS)
About | Contact | Legal Information