Skip to content

Integrate Biome into a libGDX game

Use the quickstart to try the bridge on a fixture first. The examples below integrate the same runtime into your own desktop game.

Integrate with an existing desktop game

Use a Gradle composite build to consume the runtime from the local checkout. In your game's settings.gradle, point to the checkout relative to the game's root.

includeBuild('../biome-libgdx-mcp') {
    dependencySubstitution {
        substitute(module('dev.biome.gdx:runtime')).using(project(':runtime'))
    }
}

In the Gradle module that contains the integration code, add the runtime dependency. Keep the desktop application's LWJGL3 backend and desktop natives aligned with libGDX 1.14.2.

dependencies {
    implementation 'dev.biome.gdx:runtime:0.1.0'
}

The standalone build command ./gradlew :runtime:jar produces runtime/build/libs/runtime-0.1.0.jar. The composite build resolves the runtime's transitive dependencies through Gradle. The runtime builds with a JDK 21 toolchain and emits Java 17 bytecode.

Add the following wiring to your desktop game's ApplicationListener or ApplicationAdapter. Here projectRoot is a Path for the local project directory with an assets/ subdirectory, and stage is your already-created Scene2D Stage. Keep your existing viewport, input processor, and rendering setup. The desktop fixture has a complete example. Application lifecycle · Scene2D Stage source · LWJGL3 application source

import dev.biome.gdx.BiomeRuntime;
import dev.biome.gdx.HostServices;
import dev.biome.gdx.MediaDomain;
import dev.biome.gdx.Operation;
import dev.biome.gdx.SceneDomain;
import dev.biome.gdx.ToolCatalog;

import java.io.IOException;
import java.util.LinkedHashMap;

// Fields on the application listener
private BiomeRuntime bridge;
private HostServices host;
private MediaDomain media;

// Call from create(), after creating and populating the Stage.
private void startBiome() {
    try {
        var catalog = new ToolCatalog(projectRoot);
        var operations = new LinkedHashMap<String, Operation>();
        host = new HostServices(projectRoot);
        var scene = new SceneDomain(stage, projectRoot, catalog);
        media = new MediaDomain(scene, projectRoot.resolve("assets"));
        host.register(operations);
        scene.register(operations);
        media.register(operations);
        scene.setCompilationSupplier(host::compilationStatus);
        scene.setReferenceSupplier(media::assetReferences);
        bridge = BiomeRuntime.start(projectRoot, operations, catalog);
    } catch (IOException | RuntimeException error) {
        closeBiome();
        throw new IllegalStateException("Could not start Biome", error);
    }
}

// Call in dispose(), before disposing the game's Stage and graphics assets.
private void closeBiome() {
    if (bridge != null) {
        bridge.close();
        bridge = null;
    }
    if (media != null) {
        media.close();
        media = null;
    }
    if (host != null) {
        host.close();
        host = null;
    }
}

In render(), call bridge.beforeRender() before updating the game. Gate the simulation you want the play tools to control with host.isPlaying(). Call media.tick(delta) once per frame to advance bridge-controlled media. Call bridge.afterRender() after the final draw while the framebuffer is still available. Keep all these hooks on the application render thread.

For media tools, use media.bindModel(actor, modelInstance) and media.bindParticles(actor, particleEffect) with actors attached to the Stage. The game continues to draw and dispose its own resources. Let the media domain advance bound animations and particle effects once per frame. Use media.bindAssetReferences(actor, paths) to expose project-relative asset references. Use media.declareSignal(source, signal) and media.bindSignalCallback(target, method, callback) to expose game-specific signals and callbacks. The media fixture demonstrates these bindings.

Integrate a native 3D world

Create a WorldDomain(projectRoot, mainCamera, environment) on the render thread. Register native ModelInstance objects with registerModel(id, name, instance, parentId), add perspective cameras with registerCamera, and register the directional, point, or spot lights you want to expose with registerLight. Add world.operations() to the operation map before starting the bridge. Call world.render(modelBatch) between the framebuffer clear and bridge.afterRender(). The world uses the registered active camera for this draw. Close the world on the render thread. Your game owns the registered resources and the ModelBatch. The 3D desktop fixture uses these hooks and binds a native model animation through the existing media API.