-2
\$\begingroup\$

I've created a button by checking if the left mouse button is being pressed and the cursor x/y are in the boundaries of the button but the issue is that if you even hold it down for longer than a second it receives way to much input. Is the way I'm checking if the button is pressed bad or how can I make it so this won't happen.

\$\endgroup\$
1
  • \$\begingroup\$ A lot of game libraries have these functions in their code already, OnKeyDown, OnKeyUp, OnKeyPressed, etc. Most are open source, so opening up the class that handles these functions can be of great use to creating your own or understanding the most efficient or professional way to handle things. Do not ignore Open-Source projects done by professionals. They're Open-Source!! \$\endgroup\$
    – user31214
    Jun 2, 2013 at 19:02

1 Answer 1

0
\$\begingroup\$

You need to check for a mouse state change. Only trigger a mouse down event IF the mouse was up during the last frame, and mouse is down during this frame. In some frameworks, you may need to hold on to two mouse states, one for last frame and one for this frame. The same goes for keyboard states.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .