Aug 5, 2008 at 8:14 PM
Edited Aug 5, 2008 at 8:31 PM
I am trying to allow something to happen when a player clicks a specific object, and have that something stop happening when the click again anywhere. I have it working fine all except for getting the mouse events just right. Can anyone help me find a good
way to do this?
Pseudo-code for how I'm doing it:
Collision Event handler added in the initialization that detects if the mouse cursor Geom collides with another Geom.
Collision Event Method:
if (Geom2 is correct Geom && left-click is pressed)
turn on special state
In the Update every frame method
if (special state is on && left-click is pressed && lastFrameLeft-click is released)
turn off special state
lastFrameMouseState = currentFrameMouseState
The problem lies in the if statement for the Collision Event method, because for some reason if I check for left-click pressed and previousleft-click released, it doesn't work in the collision event method, but it works fine in the Update() method in the game
What happens with the code above is that as soon as I press click to turn off special state, it turns it back on immediately because the collision event method is just looking for pressed. If I check for previousLeft-click is released in the collision event
method, it never turns on, because it doesn't work.
It would work if I were to simply check for left-click input in the Update method, and create a collision event handler if the special state is off, but I'm afraid that may use too much memory because it would create a new collisioneventhandler every single
time the user clicks and the special state is off.
Any help would be appreciated greatly.