This article has participated in the activity of “New person creation Ceremony”, and started the road of digging gold creation together.

preface

To develop a game, I believe many people have such an idea before learning development, but after learning Java, they go to the background, big data, etc. Sometimes I look back at my original aspiration and want to do something, but I have no way to start. After all, Java is not outstanding in the field of game development, and there is relatively little information. So I would like to share my experience in mining the pit here, to cast a brick to introduce jade.

The development environment

Maven: 3.8.1 Game engine: FXGL 17 GUI: javaFX

Start Hello World

Maven

<dependency>
    <groupId>com.github.almasb</groupId>
    <artifactId>fxgl</artifactId>
    <version>17</version>
</dependency>
Copy the code

Start the class HelloWorldApp

First we need to create a startup class HelloWorldApp that inherits GameApplication and implements the initSettings method to introduce the FXGL engine

public class HelloWorldApp extends GameApplication{
	@Override
    protected void initSettings(GameSettings settings) {}}Copy the code

Create a 600 x 600 form with the title “Hello World”

	@Override
    protected void initSettings(GameSettings settings) {
    	settings.setTitle("Hello world");
        settings.setWidth(600);
        settings.setHeight(600);
    }
Copy the code

main

We need to create a main method to start the program, and call FX’s launch method to start the program

	public static void main(String[] args) {
        launch(args);
    }
Copy the code

Running effect

The complete code

import com.almasb.fxgl.app.GameApplication;
import com.almasb.fxgl.app.GameSettings;

/ * * *@author lhDream
 */
public class HelloWorldApp extends GameApplication {

    @Override
    protected void initSettings(GameSettings settings) {
        settings.setTitle("Hello world");
        settings.setWidth(600);
        settings.setHeight(600);
    }

    /** * The start of the main program *@paramThe args parameter * /
    public static void main(String[] args) { launch(args); }}Copy the code

Complete the project

Github.com/lhDream/lhD…