how to avoid triggering many click event when I click once.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
liwenhaosuper
Posts: 2
Joined: Sat Jul 23, 2011 2:17 pm

how to avoid triggering many click event when I click once.

Post by liwenhaosuper »

I have created a event listener for left mouse button. However, when I click once, the event has been triggered many times.Any idea of how to avoid this problem?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: how to avoid triggering many click event when I click o

Post by Acki »

use a flag that indicates if the button is down or up...
and then, if the button is down and was previously up act on it, otherwise don't... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Re: how to avoid triggering many click event when I click o

Post by Insomniacp »

If you haven't already read the tutorials please do so,
http://irrlicht.sourceforge.net/docu/example019.html
Is for the mouse control such as a click and should be able to guide you on how to do it. If you already have then I would suggest altering your code to make it only return that the mouse is down once and then have to wait for the mouse to go up before it sends another down... Basically a flag as Acki stated but posted before I could...
blAaarg
Posts: 94
Joined: Tue Mar 02, 2010 9:11 pm
Location: SoCal

Re: how to avoid triggering many click event when I click o

Post by blAaarg »

Also, just in case, are you using "event.MouseInput.isLeftPressed () == true;" ? instead of

Code: Select all

switch (event)
{
    case: (EventType == EET_MOUSE_INPUT_EVENT)
    {
        if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
            // do your stuff here
            ...
            break;
    };
 
    case: (EventType == EET_Some_other_event_type)
    {
       // do other stuff
            ...
    };
};
because, in the first case, "isLeftPressed ()" will return true over and over again every frame until the mouse button is lifted up again, which, in the bullet-time of the computer could be several frames before your slow human finger can let go of the LMouse_button and trigger the event which sets "isLeftPress()" to false.

If that's not the case, then go with what Acki and Insomniacp said.
"Computers don't make mistakes! What they do they do on purpose!!"

-Dale Gribble
Post Reply