• 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

Key Combinations

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Philip Vaughn
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Philip,

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

Thanks
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic