Skip to main content

FlixelTeaVMLauncher

View source

class

org.flixelgdx.backend.teavm.FlixelTeaVMLauncher

public class FlixelTeaVMLauncher

Launches the web (TeaVM) version of a FlixelGDX game.

The developer creates a subclass of FlixelGame and a launcher class with a main(String[] args) method that creates the game instance and calls one of the launch overloads. Set that launcher class as the TeaVM mainClass in your web module's build.gradle.

Minimal Example

public class MyTeaVMLauncher {
public static void main(String[] args) {
FlixelTeaVMLauncher.launch(new MyGame("My Game", 800, 600, new InitialState()));
}
}

Custom Configuration Example

public class MyTeaVMLauncher {

public static void main(String[] args) {
FlixelTeaVMLauncher.launch(
new MyGame("My Game", 800, 600, new InitialState()),
FlixelRuntimeMode.DEBUG,
config -> {
config.canvasID = "my-canvas";
config.antialiasing = true;
}
);
}
}

Platform Notes

File logging is intentionally disabled on the web backend because browsers do not expose a host filesystem. The FlixelLogFileHandler is not registered, so FlixelLogger.startFileLogging() is a safe no-op. Console output uses Flixel.logConsoleSink with a styled console writer so log lines appear with readable colors in the browser; ANSI System.out is not used on web.

When Gdx.app.exit() is called, the launcher overrides exit() to invoke the browser's window.close(). Browsers only close the tab when it was opened programmatically via window.open(); for tabs the user opened directly, the browser silently ignores the request. This is a browser security restriction and cannot be bypassed from JavaScript.

The launcher automatically suppresses the browser's right-click context menu on the game canvas so that right mouse button input reaches the game unobstructed. The suppression is scoped to the canvas element only, which means right-clicking anywhere else on the page still shows the normal context menu.

Web games always pause when their tab is hidden, regardless of the auto-pause setting. The underlying WebApplication hooks visibilitychange unconditionally, and browsers throttle requestAnimationFrame heavily in background tabs regardless. This is standard browser behavior and is not something FlixelGDX can override. If your game needs to account for time spent in the background (idle progression, session timers, and similar), record a timestamp in FlixelGame.onFocusLost() and compute the delta when FlixelGame.onFocusGained() fires.

See Also: FlixelGame, WebApplicationConfiguration

Constructors

FlixelTeaVMLauncher()

public FlixelTeaVMLauncher()

Methods

launch(FlixelGame)

public static void launch(FlixelGame game)

Launches the web version of the game in RELEASE mode with default configuration.

Parameters:

NameDescription
gameThe game instance to launch (e.g. new MyGame(...)).

launch(FlixelGame, FlixelRuntimeMode)

public static void launch(FlixelGame game, FlixelRuntimeMode runtimeMode)

Launches the web version of the game with the given runtime mode and default configuration.

Parameters:

NameDescription
gameThe game instance to launch.
runtimeModeThe FlixelRuntimeMode for this session (TEST, DEBUG, or RELEASE).

launch(FlixelGame, FlixelRuntimeMode, Runnable)

public static void launch(FlixelGame game, FlixelRuntimeMode runtimeMode, Runnable onBeforeInitialize)

Launches the web version of the game with the given runtime mode, default configuration, and an optional pre-initialization callback.

Use this when you want to inject custom services without supplying a configuration customizer:

FlixelTeaVMLauncher.launch(game, FlixelRuntimeMode.DEBUG, () -> {
Flixel.setDebugOverlay(MyCustomOverlay::new);
});

Parameters:

NameDescription
gameThe game instance to launch.
runtimeModeThe FlixelRuntimeMode for this session (TEST, DEBUG, or RELEASE).
onBeforeInitializeOptional callback invoked just before Flixel.initialize. Pass null to skip.

launch(FlixelGame, FlixelRuntimeMode, Consumer<WebApplicationConfiguration>)

public static void launch(FlixelGame game, FlixelRuntimeMode runtimeMode, Consumer<WebApplicationConfiguration> configCustomizer)

Launches the web version of the game with the given runtime mode and an optional configuration customizer.

The configCustomizer receives a pre-populated WebApplicationConfiguration with sensible defaults (canvas ID, dimensions from the game). Override any field before the consumer returns. Pass null to accept all defaults.

Parameters:

NameDescription
gameThe game instance to launch.
runtimeModeThe FlixelRuntimeMode for this session.
configCustomizerOptional consumer that can modify the web configuration before the application starts.

launch(FlixelGame, FlixelRuntimeMode, Consumer<WebApplicationConfiguration>, Runnable)

public static void launch(FlixelGame game, FlixelRuntimeMode runtimeMode, Consumer<WebApplicationConfiguration> configCustomizer, Runnable onBeforeInitialize)

Launches the web version of the game with an optional pre-initialization callback.

onBeforeInitialize fires after all default FlixelGDX backend services (alerter, audio, debug overlay, etc.) have been registered but before Flixel.initialize is called. Use it to override any of those defaults without needing to duplicate the rest of the launcher wiring:

FlixelTeaVMLauncher.launch(game, FlixelRuntimeMode.DEBUG, null, () -> {
Flixel.setDebugOverlay(MyCustomOverlay::new);
});

Parameters:

NameDescription
gameThe game instance to launch.
runtimeModeThe FlixelRuntimeMode for this session.
configCustomizerOptional consumer that can modify the web configuration before the application starts.
onBeforeInitializeOptional callback invoked just before Flixel.initialize. Pass null to skip.