Results 1 to 7 of 7
Thread: Multiple keyboard presses
- 04-27-2011, 03:23 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 7
- Rep Power
- 0
Multiple keyboard presses
I am currently working on a multiplayer air hockey game which, if played by two human players from the same computer, requires the two paddles to be controlled from the same keyboard by each player (for instance).
I have created two classes which extend the Behavior class, each controlling each two paddles. processStimulus() is called every time a key is pressed however, no two keys can be pressed at once, so the game is unplayable. Is there a way to allow multiple key presses?
Thanks,
AW
- 04-27-2011, 03:40 PM #2
The general approach to this is to keep track of a boolean for each key you care about. On keyDown, set it to true, on keyUp, set it to false. Then in your game loop, check those booleans to perform the appropriate actions.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-29-2011, 08:03 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 7
- Rep Power
- 0
thank you,
if anyone has the same problem, this may come in handy Help - Swing Timer, 2 KeyEvents
SOLVED - please close
- 04-29-2011, 08:11 PM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You can mark your thread solved with the thread tools at the top of the page.
- 04-29-2011, 10:20 PM #5
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 05-01-2011, 01:00 AM #6
Be aware that you might run into hardware issues. I used to have a Microsoft keyboard on which, if more than two keys were pressed simultaneously, the release of keys after the second was not detected, simulating stuck keys.
- 05-02-2011, 04:57 PM #7
Member
- Join Date
- Apr 2011
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Keyboard
By UJJAL DHAR in forum New To JavaReplies: 4Last Post: 01-29-2011, 02:26 PM -
getting each character from keyboard
By Sreejesh25 in forum New To JavaReplies: 11Last Post: 01-25-2011, 01:08 PM -
KeyBoard Problem
By arimakidd in forum Java AppletsReplies: 3Last Post: 09-19-2008, 04:05 PM -
Responding to button presses
By Java Tip in forum javax.swingReplies: 0Last Post: 06-26-2008, 07:38 PM -
Help with keyboard events?
By Bibendum in forum New To JavaReplies: 2Last Post: 11-02-2007, 02:51 AM


LinkBack URL
About LinkBacks


Bookmarks