Search code examples
javafx-2javafx-8side-scroller

Best practice for moving characters in a game using JavaFX?


I'm making a simple sidescrolling game in JavaFX, and have done a bit of research. However, before I get really started, I wanted to make sure I was using the conventional way of creating a game. I had the following idea:

Player Characters/Enemies will extend StackPane
The levels themselves in which the players, background and enemies exist will extend Scene.
Key presses will be handled in the Level Scenes themselves, which will call the move command which exists in the player character class.
The player character will be using a custom gif image, and will use TranslateTransition for the animation of moving when keys are pressed.

Are there some obvious flaws in this approach? One thing is, I won't be using CSS, and will be raw coding the game for practice.


Solution

  • Looks good, except extending levels from Scene.

    You don't really need to change Scene in such app, only root of the scene. Thus extend levels from Pane or Parent and switch them by Scene#setRoot() to avoid extra stuff in your classes you don't need.