Sunday, March 22nd, 2009, 12:56 am | Computer, Download, Experiments, Gaming, Hardware, Programming, Software

MultiInput class – multiple mice in your XNA game!

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

multiinputgame_alpha_01

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

using MultiInput;

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();         }     }
VN:F [1.0.7_345]
Rating: 8.2/10 (6 votes cast)



9 Responses to “MultiInput class – multiple mice in your XNA game!”

  1. weilin Says:

    Very nice…It won’t work with my touch screen/stylus though. And the sensitivity is either off or its lagging.

    VA:F [1.0.7_345]
    Rating: 5.0/5 (1 vote cast)
  2. Lennart Moltrecht (admin) Says:

    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!

    VN:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  3. Airship Assault - First game using MultiInput-technology » multimolti’s Techblog Says:

    [...] 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 [...]

  4. Alejandro Says:

    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/

    VA:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  5. Lennart Moltrecht (admin) Says:

    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.

    VN:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  6. Eric Bergman Says:

    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?

    VA:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  7. Eric Bergman Says:

    for (int i = 0; i < inputController.MiceCount; i++)

    Error 1 The name ‘lt’ does not exist in the current context

    VA:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  8. Lennart Moltrecht (admin) Says:

    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

    VN:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)
  9. Lennart Moltrecht (admin) Says:

    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.

    VN:F [1.0.7_345]
    Rating: 0.0/5 (0 votes cast)

Leave a Reply

ss_blog_claim=c7d0757dcb48491268e39569f229169b ss_blog_claim=c7d0757dcb48491268e39569f229169b