Friday, May 04, 2007

XNA Mouse and Sprite Tests

Played around with XNA last night again. For the card game I need to be able to display cards on the screen and click a stack of them to deal another card onto it.

So there's two basic things there that I need: display cards, and control the mouse.

I just followed the example for How To Draw a Sprite and I think that this will be all I need to draw cards to the screen. I'm pretty sure I know how to use the SpriteBatch and Texture2D classes now, but whether or not I'm using them correctly is another thing. All I can say is, I followed the examples and it works.

So I looked into showing the mouse pointer. I found a good article about encapsulating the mouse functionality into a class, and I'll probably follow this to tidy up my code, but for now I've just put that in my main Game class.

So I drew a pointer in MSPaint and used that as my cursor. I don't have the DirectX SDK yet (couldn't be bothered to download it last night), so the pointer isn't masked in the way that is described. It looks a little odd having a block of white surrounding the pointer, but for a proof of concept it's fine.

It struck me as odd that there wasn't a simpler way to show the mouse. Maybe there is and I just haven't found it, but then I though that the way I'm using is very flexible. It gives me full control of when I show the mouse, and I can update it only when I need to. Why have needless processing of the mouse when you're in a section of game that doesn't require it?

So for now I've got a random card showing on my screen (which I can show in full screen mode and at a really nice resolution, but that's another story), a pointer on the screen, and a continuously updating line of text which tells me where the pointer actually is.

I'm still a long way from a playable game, but I think I'm beginning to get the basics.


Mykre said...

When using XNA You can just turn on the mouse pointer, Here is a link to a tutorial I wrote on the subject.

And here is a tutorial for a custom Mouse Pointer.

Hope they help you out.

Ian Dykes said...

Thank you!

I knew I had seen the IsMouseVisible property somewhere, but couldn't find it again. Now you've said this it's so obvious that that would be where it would be.

Although I think I'll stay with the custom mouse pointer that you highlight in your second tutorial for now as it does give me more freedom.

Ken said...

Hi. I am trying to make a card game with XNA. I've been looking for examples, do you have a tutorial or project I can download so I know how to get started. The XNA examples were confusing for me.