| Author |
Multiple Event Handling
|
john price
Ranch Hand
Joined: Feb 24, 2011
Posts: 495
|
|
How do you handle multiple events at the same time? For example, I have a game. I want to push the right arrow along with the up key. How would I be able to receive the input at the same time?
Looks something like this :
Thanks,
John Price
|
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
|
 |
john price
Ranch Hand
Joined: Feb 24, 2011
Posts: 495
|
|
I figured it out thanks. What I did to "fix" the problem was to not stop the thread until the keyReleased method was set off by that key (an additional switch statement in my case with "VK_RIGHT" and "VK_LEFT")
Thanks,
John Price
EDIT :
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Usually something like this is the approach to go for. On key pressed you store the keys somewhere, and on key released you remove them from the storage. All keys in the storage are then the currently pressed keys.
However, moving = false may be premature. What if I still have UP pressed? Aren't I then still moving?
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
john price
Ranch Hand
Joined: Feb 24, 2011
Posts: 495
|
|
For pressing up, it activates another variable, left and right are on the "moving" variable and up is on a separate variable.
John Price
|
 |
 |
|
|
subject: Multiple Event Handling
|
|
|