Friday, March 09, 2007

MOUSE2D GAME COMPONENT FROM TEHONE.COM has published a mouse component for XNA.

From TehOne's post: "Here is my Mouse2D DrawableGameComponent. I started out just wanting to be able to put a custom Mouse pointer/cursor on the screen instead of the windows mouse. From there the code just seemed to keep evolving more and more. After I got my custom pointer on the screen, I wanted to then place a Texture2D where it clicked (this was mostly for debugging etc, but I think turned out to be useful for other things). I could see this feature being used in map editors maybe, or something where you want to give the user the ability to design what they see on the screen."

You can download the source code and or a demo game, and check the online documentation ... and please, don't forget to read the license.

"As always, I would really appreciate some feeback on this. I'm sure people can make use of this code (especially beginers). And I'm even more sure that it can be improved with input from others (especially those with more experience then me)."

Let's give the guy some feedback.


  1. Thanks! Sorry for the demo game being so simplistic though.

  2. Why? It's ok for a demo ...

    BTW, I like the way you do all the comments stuff in your source code.

  3. One suggestion though: instead of labeling a region "Internal Classes" you'd better use "Nested Classes".

    Also, and this is a big maybe because it depends on what you were looking for, instead of creating one event for each mouse button, it would be better to create one event for all buttons, what means that you'll need to change your ClickEventArgs class, by adding a new field/porperty that return the ClickButtonType. Again, just a suggestion ...

  4. Yeah, I had thought about doing just that, but I figured for ease of use, it's easier to just hook into the button event you need. Otherwise, you would have to handle the ClickButtonType and also the state on the event every time you want to use it. I thought by seperating them the way that I did, it makes implemenation easier if your just looking for a quick way to capture a left click for example. That way you don't have to handle the click and then try to manually figure out if it was a left lick or not. What do you think about me leaving what is there, but adding a new generic event like suggested?

    Thanks again.

  5. "What do you think about me leaving what is there, but adding a new generic event like suggested?"

    Nooo, it was just an idea. There are different ways of implementing the same feature. For instance, instead of using an interface like IXnaGameComponent, you could just use the following in the mouse component:


    ... since your "MousePointer2D" class is an specification of the base "Microsoft.Xna.Framework.DrawableGameComponent" class, you don't need to check if the component is enabled/visible because the main loop does the check/call for you when you register the component in the proper collection.

    But again, depending on what are you looking for it's argueable.

    Go on with your current implementation. You're doing a great job!


Any thoughts? Post them here ...