• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple Event Handling

 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For pressing up, it activates another variable, left and right are on the "moving" variable and up is on a separate variable.

John Price
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic