File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JavaFX and the fly likes Key Combinations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JavaFX
Bookmark "Key Combinations" Watch "Key Combinations" New topic
Author

Key Combinations

Philip Vaughn
Greenhorn

Joined: Jan 04, 2014
Posts: 6
Ok, I'm creating an RPG style game with FX and need help with key inputs. Basically whenever the user presses the arrow keys (down, left, right, up) the player character will move on the map. This all works well enough but I need to be able to have the player run. So I'm using the SHIFT key for running. The problem comes when I press the shift key. If I have one of the arrow keys pressed down when I press the shift key it cancels the current arrow key and I have to press it again to move. So basically if I press shift and then an arrow key it works fine but if I press the arrow key and then shift the player stops moving. The code for when I press the shift key simply increases a variable called "moveSpeed" by 1 ( it should do this without cancelling the keys I already have pressed) and when I release the shift key it decreases "moveSpeed" by 1. I've tried key combinations with arrow keys and "shift.down" and I've tried just single keycode.shift but it always stops the current key press. I have a <KeyEvent> that handles all of this together.

Can anyone give me a hand with this?
John Damien Smith
Ranch Hand

Joined: Jan 26, 2012
Posts: 144
    
    9
Philip Vaughn
Greenhorn

Joined: Jan 04, 2014
Posts: 6
Well being 1AM I'm not going to test this tonight but your code looks very good. I'll test it tomorrow and let you know. I'm still trying to get used to JavaFX with all the timers and and animation abilities.
Philip Vaughn
Greenhorn

Joined: Jan 04, 2014
Posts: 6
Sorry for the double post but I wanted to let John Damien Smith know that the code you posted worked absolutely perfectly! Everything about it is streamline. There's no glitchiness (not a word, I know lol) in the movement and the running works just like it should. Thanks much!
John Damien Smith
Ranch Hand

Joined: Jan 26, 2012
Posts: 144
    
    9
Philip, you might also be interested in discussions around a a Multi-threaded game loop in JavaFX which have occurred over on the JavaFX forum.
Philip Vaughn
Greenhorn

Joined: Jan 04, 2014
Posts: 6
I have another question about javafx actually. I need to be able to adjust the "z" values of nodes within a javafx pane. I know you can use a stackpane but stackpane does not work for me because I need absolute positioning of the nodes (ie the player walking around the map). So I've resorted to using just regular Pane but whenever I try to change the index of a node within the Pane it doesn't draw it above or behind another. I'm not sure why. I've went as far as clearing the node and adding all the children back in a certain order but the depth is never changed for some reason. Basically, my player that is walking around the screen needs to be on top of other characters if his "y" value is greater than theirs. If the player's "y" value is less than it needs to appear that he's behind the other characters. Any ideas?
John Damien Smith
Ranch Hand

Joined: Jan 26, 2012
Posts: 144
    
    9
Hi Philip,

Can you ask you question in a new question and include an sscce?

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Key Combinations