JavaFX Launcher

JME JavaFX Launcher

Requires: Java 11

An implementation of a JavaFX launcher that replaces the built-in Settings Dialog. Very similar to the “Fallout 4” style launcher, whereby when you start the game you get the launcher first before playing the game.

The launcher allows the user to select:

  • Full Screen Mode
  • Resolution
  • Anistropic Filtering
  • Anti-Aliasing
  • Ambient Occlusion
  • Bloom
  • Depth of Field

These settings and filters are applied (or not) automatically.

Settings are saved as JSON and are therefore persistent. The launcher is customizable and will also allow you to restart your game. This means the user can also modify things in-game (e.g. anistropic filtering or something that requires a restart).

This also serves as a “working version” of how to go about creating a launcher yourself - something a lot of people have been interested in doing.

import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.post.FilterPostProcessor;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;

import java.io.File;

public class Main extends SimpleApplication implements ActionListener {

    public static void main(String... args) {

        JfxLauncher.initialize(Main.class);
        JfxLauncher.getInstance().setTitle("Some Amazing Game");
        JfxLauncher.getInstance().setSettingsFile(new File("./settings.json"));
        JfxLauncher.getInstance().show();

    }

    @Override
    public void simpleInitApp() {

        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
        viewPort.addProcessor(fpp);

        JfxLauncher.getInstance().applySettings(fpp);

        // create a scene...
        Geometry box = new Geometry("Box", new Box(1,1,1));
        box.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
        box.getMaterial().setColor("Color", ColorRGBA.Blue);

        rootNode.attachChild(box);

        // add a keybinding to test restart mode.
        inputManager.addMapping("restart", new KeyTrigger(KeyInput.KEY_R));
        inputManager.addListener(this, "restart");
    }

    @Override
    public void onAction(String name, boolean isPressed, float tpf) {

        if (name.equals("restart") && !isPressed) {
            JfxLauncher.getInstance().setRestart(true);
            stop(true);
        }

    }

}

Source Code

Source code is - as always - available on GitHub. It will also be made available on jMonkeyStore as soon as I get a moment to add it.

Demonstration App

Download and double-click the jar to run, or

java -jar jme-jfx-launcher-1.0-all.jar

https://github.com/jayfella/jme-jfx-launcher/releases/download/1.0.1/jme-jfx-launcher-1.0.1-all.jar

10 Likes

v1.0.1

  • Fixed a bug where I didn’t save the resolution ComboBox changes.
  • Added the ability to restart.
  • Updated the test Main.class to show how to restart the game.
2 Likes

Looks great, and easy to setup! Maybe this is a JME thing, but I don’t see “settings.json” anywhere in the project? is that for JME settings I guess?

Anyway, this is very nice! Here is what I did with it. Going to refresh my javafx and skin the buttons next :slight_smile:

image

2 Likes

what do you mean by “JME settings”?

you mean settings file for panel with settings that appear before game run?

Myself i use java Properties class for everything related, save it into storage defined folder and read as “remembered settings”.(setting values from it)

When you first run the launcher it will create the settings.json file. One isn’t included because it’s auto-generated, and you can specify a path if you don’t want it making a mess in the root of your game folder.