How do I identify mouse clicks versus mouse down in games?

Posted by Tristan on Game Development See other posts from Game Development or by Tristan
Published on 2011-08-20T15:56:34Z Indexed on 2012/10/15 15:55 UTC
Read the original article Hit count: 378

Filed under:
|
|

What is the most common way of handling mouse clicks in games?

Given that all you have in way of detecting input from the mouse is whether a button is up or down.

I currently just rely on the mouse down being a click, but this simple approach limits me greatly in what I want to achieve. For example I have some code that should only be run once on a mouse click, but using mouse down as a mouse click can cause the code to run more then once depending on how long the button is held down for. So I need to do it on a click!

But what is the best way to handle a click? Is a click when the mouse goes from mouse up to down or from down to up or is it a click if the button was down for less then x frames/milliseconds and then if so, is it considered mouse down and a click if its down for x frames/milliseconds or a click then mouse down?

I can see that each of the approaches can have their uses but which is the most common in games? And maybe i'll ask more specifically which is the most common in RTS games?

© Game Development or respective owner

Related posts about input

Related posts about mouse