XNA Mouse "Clicks"
So I've been carrying on with my card game in XNA. I've created some crude textures for the empty card "slot" and managed to find some pictures of playing cards online that I can use for the card faces.
One of the first things I did was sort out all the back end stuff (like shuffling the deck, dealing a card, etc.), I just needed to capture a mouse click on an empty card stack and deal a card.
But when it came to detecting the mouse click I was surprised that not 1 card was dealt when I clicked a card stack, but pretty much half of the deck.
I was using the Mouse.GetState method to check if the LeftButton was Pressed. As this was happening in the Update loop the game was looping around multiple times for as long as I kept the mouse button down.
Pressed really does mean Pressed.
So now I'm storing the previous state of the mouse, and only when the LeftButton state goes from Pressed to Released do I count a click.
EDIT: Detecting Pressed to Released models a "MouseUp" event, and while this may be useful in some situations, in this game a "MouseDown" would make more sense. To detect a MouseDown you count a click as the state going from Released to Pressed.
Now I just need to implement the rules of the game, and some scoring mechanism so scores can be compared.
3 comments:
"So now I'm storing the previous state of the mouse, and only when the LeftButton state goes from Pressed to Released do I count a click"
I would make it a click when the button goes from Released to Pressed.
Thanks,
Ziggy
Ziggyware XNA News and Tutorials
Interesting point, and I suppose it does make more sense to do it this way.
What I'm mimicking currently is really a "MouseUp" event, while Released->Pressed is more a "MouseDown" event.
It would certainly make the interface more responsive.
Thanks!
I put together a small input manager system that might help.
Here is the link for you, http://www.virtualrealm.com.au/forums/t/256.aspx
Post a Comment