Skip to content

Your first application

A SimpleApplication gives you the essentials for a jMonkeyEngine game: a scene root, camera, input manager and asset manager. The Initializer generates launchers for your selected platforms, each of which starts your shared game class. Place shared game logic in the app module and assets in game-assets/src/main/assets/ so every launcher can use them.

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;

public class HelloWorld extends SimpleApplication {
    public static void main(String[] args) {
        new HelloWorld().start();
    }

    @Override
    public void simpleInitApp() {
        Geometry box = new Geometry("Box", new Box(1, 1, 1));
        Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        material.setColor("Color", ColorRGBA.Yellow);
        box.setMaterial(material);
        rootNode.attachChild(box);
    }
}

The engine calls simpleInitApp() once when the application starts, making it a convenient place to create the initial scene. For behavior that changes over time, use simpleUpdate(float tpf), which runs each frame. Its tpf argument is the elapsed time in seconds, so multiplying a movement speed by tpf makes motion less dependent on frame rate. Specialized rendering can use simpleRender(), while reusable application features can be organized into AppStates.

The yellow box uses an unshaded material so it is visible without lighting. For game assets, continue with glTF and PBR.