Help with making an event when mouse button is released

Started by aerguin, Sat 26/05/2007 18:06:42

Previous topic - Next topic

aerguin

Hi there,
I'm just starting to write a game and I'm having a bit of trouble when handling an event when a mouse button is RELEASED.
The thing is that I want a GUI window to appear when the right button is pressed, no problem there. I don't want the window to stay there when the button is released, I want to make it dissappear exactly when that right button is released.
I've done it this way after the GUI is visible with the click:

while (MouseRightButtonPressed = TRUE)
{
}
GUI.Dissapear();

This won't work because the program gets kind of stuck in the While-loop and the cursor won't move and nothing will happen while the button is pressed.
Another way I tried was to put a Wait(1) inside the While. This kind of works, but as the game goes into the Pause/Wait mode, the buttons in the GUI appear unavailable and don't change of image when I place the mouse above them, and this is exactly what I want to happen.
So I see no way around it... I can think of 2 possible ways but none work. One would be to somehow keep the program inside the While-loop but without blocking the usual mouse movements and GUI button behaviours. Another would be just to get rid of the While-loop, and create an event or function when the mouse button is released to make the GUI dissappear.
Any help?
Thanks.

Gilbert

Use a variable to keep track of the button status.

When it's pressed, set it to 1.
Then check in repeatedly_execute() with mouse.IsButtonDown(), if that variable's value is 1 and the button is not pressed set the variable back to 0 and remove the GUI.

Something like that.

aerguin

 :D That was so fast and worked!
I finally didn't use the variable, just checked if the GUI was visible at the same time as the mouse released, wich is the same idea.
Thanks a lot!

SMF spam blocked by CleanTalk