Results 1 to 1 of 1
- 11-17-2008, 06:51 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 44
- Rep Power
- 0
ZombieEscape: Multiple KeyBinding at one moment?
Hi Guys! Unome again. The JavaApplet I've been working on is becoming a killer success. My character now has an environment it can explore. He can jump, run, crouch, heal, commit suicide, pause, restart.... and a variety of other things... My main problem at the moment is this:
I cannot perform multiple actions at once:
Situation: Player is pressing the forward key, and then strikes jump(still holding forward key)
RESULT: In normal games you would jump forward... When I strike the jump action the forward action is canceled and he jumps straight up.
HOWEVER: If I strike the keys at the exact same time (kinda hard) he jumps forward.
Same priuncipal apply's when firing gun, jumping, crouching, healing ect...
Heres my action code:
PHP Code:...................... .................... private void bindKeys() //sets up key actions for the program { JRootPane rp = getRootPane(); int c = JComponent.WHEN_IN_FOCUSED_WINDOW; InputMap inputMap = rp.getInputMap(c); ActionMap actionMap = rp.getActionMap(); inputMap.put(KeyStroke.getKeyStroke("LEFT"), "LEFT"); //creates left action actionMap.put("LEFT", walkleft); inputMap.put(KeyStroke.getKeyStroke("RIGHT"), "RIGHT"); //creates right action actionMap.put("RIGHT", walkright); inputMap.put(KeyStroke.getKeyStroke("SPACE"), "SPACE"); //creates space action actionMap.put("SPACE", fireball); inputMap.put(KeyStroke.getKeyStroke("P"), "P"); //creates space action actionMap.put("P", pause); ............................. ............................. ............................ private AbstractAction walkleft = new AbstractAction() { //action that moves the ball left public void actionPerformed(ActionEvent e) { Moveball.moveleft(); } }; private AbstractAction walkright = new AbstractAction() { //action that moves the ball right public void actionPerformed(ActionEvent e) { Moveball.moveright(); } }; .................. ..................
I think the trick lies in the "WHEN_IN_FOCUSED_WINDOW" I'm not quite sure though.
Mmk Java Jenius's. Can you solve this error?
Similar Threads
-
Use multiple forms
By coco in forum Java AppletsReplies: 2Last Post: 06-14-2010, 05:14 AM -
[SOLVED] Resize error? ZombieEscape
By Unome in forum Java AppletsReplies: 9Last Post: 11-17-2008, 06:43 PM -
Multiple Users
By peiceonly in forum Threads and SynchronizationReplies: 5Last Post: 06-09-2008, 09:17 AM -
Need help with T/F and Multiple Choice
By sayso36 in forum Advanced JavaReplies: 0Last Post: 03-12-2008, 04:39 PM -
Multiple Inheritance
By mew in forum New To JavaReplies: 1Last Post: 12-01-2007, 10:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks