Mazela-Man

FXGL Tutorial

In this tutorial we will build a simple game using FXGL - a Java / JavaFX / Kotlin Game Library. FXGL is built on top of JavaFX, but you don’t need to know JavaFX to follow the tutorial. We will use version 11.13 of FXGL.

The tutorial is divided into a number of chapters that each introduces a new part of the game, and usually a new part of FXGL. Each chapter builds on the previous, so it’s advisable to read and execute them in order. The tutorial is accompanied by a Maven project with one module per chapter, each containing the code for the game as it is at the beginning of the chapter. The Maven project can be found in repository mazela-man. Following the tutorial closely will result in code that looks like the code contained in the following chapter. Experimentation is encouraged, but if you lose your way in the process, you can always start over with a working code base in the following chapter.

All resources used in the tutorial, and a few extras, can be found here.

Requirements

If you are content with just reading through the tutorial, you can start right away, but if you also want to write code and run the game, you need to install some software on your computer. The following pieces of software are needed to follow the tutorial:

  • Java 11. FXGL version 11.13 requires Java 11 or later.
  • Tiled 1.2.3. FXGL works best with version 1.2.3 of the Tiled map editor. You only need to install Tiled if you want to edit level files yourself. Otherwise, you can just copy the edited file from the next chapter. If you are new to Tiled, you can read the introduction on their website.
  • IntelliJ IDEA (recommended), Eclipse, or another IDE.
  • Maven. The tutorial is a Maven project, and you need Maven to build it. Maven may or may not be included in your IDE. If you are new to Maven, you may want to read this five minute tutorial.

You also need to clone the Git repository of the tutorial. You can do this directly in your IDE, or you can do it on the command line, and then open the tutorial as a Maven project in the IDE.

> git clone https://github.com/dykstrom/mazela-man.git

Getting Started

The best way to start is from the beginning.

You can also jump directly to a specific chapter:

Glossary

Terms used in the tutorial, explained in the context of FXGL.

  • bounding box - an invisible box around an entity that can be checked for collisions
  • callback - a call from the framework to a method in your code
  • component - an independent part of an entity that is responsible for some part of the entity’s functionality
  • entity - a game object; an object that exists in, and can interact with, the game world
  • facade - a class that serves as the interface to a system, hiding complex functionality from the client
  • frame - one iteration of the game loop; all entities, and their components will be updated once per frame
  • physics engine - a component that provides a simulation of the physical world with for example gravity and collisions
  • tile - a small rectangular image used repeatedly to create a level or once to represent an entity
  • time per frame (tpf) - the amount of time that has passed in the game world since the previous update

Resources

Credits

Graphics by drakzlin at OpenGameArt.org. Sounds from FXGL samples, and Classic Gaming.