• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple Event Handling

 
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 :
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic