JavaFX Game tutorials ?

I am looking for some JavaFX game related tutorials, books or videos

I Have found these so far

and here some videos, didn’t see it yet

do anyone have some more information on JavaFX games ?

I know JavaFX is not the best suited tool for games better use x, y or z, blah, blah, blah :slight_smile:
I just want to give a try for myself.


Well I got the time to put toguether a simple barebones example of a JavaFX 8 Game loop
maybe not the best but it get the work done.

package library;

import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.geometry.Bounds;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class MainLoop extends Application {

	//size in pixels of the main game canvas
	private final int SIZE_W = 800;
	private final int SIZE_H = 600;
	//one second in nanoseconds
	private final long ONE_SECOND = 1000000000;
	//used to store the current time to calculate fps
	private long currentTime = 0;
	//used to store the last time to calculate fps
	private long lastTime = 0;
	//fps counter
	private int fps = 0;
	//acumulated difference between current time and last time
	private double delta = 0;
	//text to display fps
	private Text tFPS;
	//the game loop timer
	private AnimationTimer mainLoop;
	//the shape to test the main loop
	private Polygon star;
	//direction x,y of the star shape 
	private int dirx = 1;
	private int diry = 1;
	public void start(Stage stage) throws Exception {
		//main game canvas
		Pane root = new Pane();
		root.setPrefSize(SIZE_W, SIZE_H);
		root.setBackground(new Background(new BackgroundFill(Color.BLACK, null, null)));
		//initialize all objects of the main loop
		//define the main loop
		//main scene
		Scene scene = new Scene(root);
		//the main window
		stage.setOnCloseRequest(event -> {
		//start the main loop
	public void initNodes(ObservableList<Node> rootPane){
		tFPS = new Text("FPS : ");
		tFPS.setFont(new Font(40));
	public void initAnimation(ObservableList<Node> rootPane){
		star = new Polygon();
		Double[] starCoord = new Double[]{ 
				35.0, 120.5, 37.9, 129.1, 46.9, 129.1, 39.7, 134.5, 42.3,
				143.1, 35.0 , 139.0, 27.7, 143.1, 30.3, 134.5, 23.1, 129.1,

	public void initMainLoop(ObservableList<Node> rootPane){
		lastTime = System.nanoTime();
		mainLoop = new AnimationTimer() {
			public void handle(long now) {
				currentTime = now;
				delta += currentTime-lastTime;
				if(delta > ONE_SECOND){
					tFPS.setText("FPS : "+fps);
					delta -= ONE_SECOND;
					fps = 0;
				lastTime = currentTime;
	public void updateAnimation(ObservableList<Node> rootPane){
		Bounds starbounds = star.getBoundsInParent();
		double posx = star.getTranslateX();
		double posy = star.getTranslateY();

		if((starbounds.getMaxX() >= SIZE_W) || (starbounds.getMinX() <= 0.0)){
			dirx = -dirx;
		if((starbounds.getMaxY() >= SIZE_H) || (starbounds.getMinY() <= 0.0)){
			diry = -diry;

	public static void main(String[] args){


more info here:

hope somebody found this usefull.

Thanks for this. Some good tutorails there :slight_smile:

A new book on JavaFX game programming has recently been released.

You can download the source code from the link.

@AllanM I just came across the book you linked (Beginning Java 8 Games Development, Wallace Jackson) on Safari online, via my public library while looking for a good intro to JavaFX. Chapter 4 seems to be the key. How is it working for you?

Are you taking the NetBeans route it recommends?

I’ve mostly limited myself to Java2D for graphics, but am thinking of investing some time into learning JavaFX for a couple of reasons. For one, Oracle is committed to developing JavaFX going forward as the main library for graphics, rather than doing more with AWT or Swing. For another, it seems more likely that initiatives such as RoboVM are more likely to first support JavaFX than Swing.

Came across some more resources. I’ve started to work through this book:
JavaFX 8, Introduction by Example, Carl Dea

It has a little section with some game-oriented references that look promising (haven’t checked them out yet):

I decided to ditch the “JavaFX Introduction by Example”. It’s probably fine if you are the type that has read and understands “Effective Java” by Bloch. It’s probably also fine if you don’t mind learning all about abstract concepts pertaining to lambdas before even getting to basics of layout, or mind mastering conceptual definitions of “Node” prior to actually programming a Button.

I’m reading “JavaFX for Dummies” and learned more useful stuff in 1 hour than I did struggling with the Dea book over three torturous sessions. (Am reading via public library online utilities.)


Although I would go for LibGDX instead of JavaFX :point: But hey, everyone got their own reasons :slight_smile: