![]() |
|
Debouncing a mouse click? |
nshade
Member #4,372
February 2004
|
Man I feel like I'm posting in here every day. I guess if I come in with code and at least try I feel like I'm not bothering you all. Given this psudocode: 1bool debounce = false;
2while (1)
3{
4 if (state.buttons & 1)
5 {
6 // Primary (e.g. left) mouse button is held.
7 printf("Mouse position: (%d, %d)\n", state.x, state.y);
8 //Hold debounce = true here so it only iterates once?
9 }
10
11 if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP)
12 {
13 //release debounce = false so it can trigger again?
14 }
15}
The program will spit out X and Y position for as long as the mouse is down... How Would one "one shot" this so that only one position is captured until the button is lifted. I think my logic is faulty. I tired a few iterations of this and it didn't seem to work... EDITnever mind, my brain is dumb - This is what I'm looking for 1al_get_mouse_state(&state);
2if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
3{
4 printf("Mouse position: (%d, %d)\n", state.x, state.y);
5}
|
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Hello nshade, Don't mix state and events like that. Use one or the other (events). Look at the classic event loop on the wiki : https://wiki.allegro.cc/index.php?title=Allegro_5_API_Tutorials https://wiki.allegro.cc/index.php?title=Allegro_5_Tutorial/Events My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|