FlixelGame
View sourceclass
org.flixelgdx.FlixelGame
The game object used for containing the main loop and core elements of the game.
To actually use this properly, you need to create a subclass of this and override the methods you want to change. It is strongly advised that you do NOT use this class to add the main gameplay logic to your game. Your code should go into your FlixelStates or libGDX Screen implementations instead.
It is recommended for using this in the following way:
// Create a new subclass of FlixelGame.
// Remember that you can override any methods to add extra functionality
// to the game's behavior.
public class MyGame extends FlixelGame {
public MyGame() {
super("My Game Title", 640, 360, new InitialState());
}
}
Then, in a platform-specific launcher, you can create a new instance of your game and run it:
// Example of how to create a new game instance and run it using the LWJGL3 launcher.
public class Lwjgl3Launcher {
public static void main(String[] args) {
if (StartupHelper.startNewJvmIfRequired()) {
return;
}
FlixelLwjgl3Launcher.launch(new MyGame());
}
}
Constructors
FlixelGame(String, FlixelState)
Creates a new game instance with the details specified.
Parameters:
| Name | Description |
|---|---|
title | The title of the game's window. |
initialState | The initial state to load when the game starts. |
FlixelGame(String, int, int, FlixelState)
Creates a new game instance with the details specified.
Parameters:
| Name | Description |
|---|---|
title | The title of the game's window. |
width | The starting width of the game's window and how wide the camera should be. |
height | The starting height of the game's window and how tall the camera should be. |
initialState | The initial state to load when the game starts. |
FlixelGame(String, int, int, FlixelState, int)
Creates a new game instance with the details specified.
Parameters:
| Name | Description |
|---|---|
title | The title of the game's window. |
width | The starting width of the game's window and how wide the camera should be. |
height | The starting height of the game's window and how tall the camera should be. |
initialState | The initial state to load when the game starts. |
framerate | The framerate of how fast the game should update and render. |
FlixelGame(String, int, int, FlixelState, int, boolean)
Creates a new game instance with the details specified.
Parameters:
| Name | Description |
|---|---|
title | The title of the game's window. |
width | The starting width of the game's window and how wide the camera should be. |
height | The starting height of the game's window and how tall the camera should be. |
initialState | The initial state to load when the game starts. |
framerate | The framerate of how fast the game should update and render. |
vsync | Should the game use Vsync to limit the framerate to the monitor's refresh rate? |
FlixelGame(String, int, int, FlixelState, int, boolean, boolean)
Creates a new game instance with the details specified.
Parameters:
| Name | Description |
|---|---|
title | The title of the game's window. |
width | The starting width of the game's window and how wide the camera should be. |
height | The starting height of the game's window and how tall the camera should be. |
initialState | The initial state to load when the game starts. |
framerate | The framerate of how fast the game should update and render. |
vsync | Should the game use Vsync to limit the framerate to the monitor's refresh rate? |
fullscreen | Should the game start in fullscreen mode? |
FlixelGame(String, int, int, Supplier<FlixelState>, int, boolean, boolean)
Creates a new game instance with the details specified.
Parameters:
| Name | Description |
|---|---|
title | The title of the game's window. |
width | The starting width of the game's window and how wide the camera should be. |
height | The starting height of the game's window and how tall the camera should be. |
initialStateFactory | The initial state to load when the game starts as a supplier factory. |
framerate | The framerate of how fast the game should update and render. |
vsync | Should the game use Vsync to limit the framerate to the monitor's refresh rate? |
fullscreen | Should the game start in fullscreen mode? |
Fields
title
The initial title displayed on the game's window. Only used at startup time during the game's boot sequence.
initialSize
The size of the game's starting window position and its first camera. Only used at startup time during the game's boot sequence.
initialStateFactory
Produces the root FlixelState each time FlixelGame.create() runs. Use () -> new MyState() for a fresh instance per session, or () -> sharedState to reuse one object (its FlixelState.destroy() / FlixelState.create() lifecycle still runs via Flixel.switchState(FlixelState)).
batch
The main batch used for rendering all sprites on screen.
bgColor
The background color of the entire game's window (full-framebuffer clear before camera passes).
bgTexture
1x1 white texture used to draw solid fills (camera bg, FX); tinted via FlixelSpriteBatch.setColor(Color).
cameras
Convenience reference to the global Flixel.cameras list (the single source of truth).
fullscreen
Whether the game should start in fullscreen mode. Only used at startup time during the game's boot sequence.
transparentFramebufferRequested
When true, the launcher requests an alpha-capable framebuffer so FlixelWindow.setTransparencyActive(boolean) can composite with the desktop.
Set false before launch only for drivers or projects that must keep a strictly opaque default framebuffer.
WARNING: This can cause some minor performance issues on low-end devices, so only enable this at launch time if you truly need to!
autoPause
Should the game pause audio when the application goes to the background?
resetRequested
When true, calls FlixelGame.destroy() and FlixelGame.create(), which resets the game.
Methods
create()
Called when the game is created. This is where you should initialize your game's resources.
This method configures the crash handler, sets up input processing, initializes the debug overlay, configures the ANSI system for color output in terminals, and then switches to the initial state.
This method is called automatically by libGDX's ApplicationListener.create() method when the game is created, so it is not necessary to call this method manually in most cases. However, it can be overridden to perform custom initialization before the game is created.
See Also: ApplicationListener.create()
resize(int, int)
update(float)
Updates the logic of the game loop.
Parameters:
| Name | Description |
|---|---|
elapsed | The amount of time that occurred in the last frame. |
draw(FlixelBatch)
Updates the graphics and display of the game.
Parameters:
| Name | Description |
|---|---|
batch | The batch to use for drawing the game. |
render()
Updates the game's global and internal FlixelGame.update(float) and FlixelGame.draw(FlixelBatch) methods, with elapsed time clamped to the min and max values to prevent major lag spikes.
This method is called automatically by libGDX's ApplicationListener.render() method when the game is running.
You should not (and cannot) override this method. You are encouraged to override either FlixelGame.update(float) or FlixelGame.draw(FlixelBatch) instead, as they separate logic and rendering correctly.
See Also: .update, .draw, ApplicationListener.render()
setGamePaused(boolean)
Pauses the game's update loop. This is mostly used by the debugger, although you might find it useful for other purposes.
Parameters:
| Name | Description |
|---|---|
gamePaused | Whether the game should be paused or not. |
pause()
Do not override this method. Override FlixelGame.onFocusLost() instead.
resume()
Do not override this method. Override FlixelGame.onFocusGained() instead.
onFocusLost()
Called when the game window loses focus or the application goes to the background.
On mobile and web this fires when the OS sends the application to the background. On desktop it fires when the game window loses focus or is minimized (focus loss always arrives before minimize, so this is called once for both events).
The default implementation pauses audio and stops continuous rendering when FlixelGame.autoPause is true, then notifies the active state. Duplicate calls without an intervening FlixelGame.onFocusGained() are silently ignored.
See Also: .onFocusGained, .onMinimized, Flixel.Signals.windowUnfocused
onFocusGained()
Called when the game window regains focus or the application returns to the foreground.
On mobile and web this fires when the OS brings the application back to the foreground. On desktop it fires when the game window gains focus, including when the window is restored from being minimized.
The default implementation resumes audio and re-enables continuous rendering when FlixelGame.autoPause is true, then notifies the active state. Calls that arrive without a prior FlixelGame.onFocusLost() are silently ignored.
See Also: .onFocusLost, Flixel.Signals.windowFocused
onMinimized()
Called when the desktop window is minimized (iconified).
This is a desktop-only event and is never called on mobile or web platforms. On most operating systems, focus loss fires first so FlixelGame.onFocusLost() already handles audio and rendering pausing before this is called.
The default implementation notifies the active state and dispatches Signals.windowMinimized.
See Also: .onFocusLost, .onFocusGained, Flixel.Signals.windowMinimized
setFullscreen(boolean)
Sets fullscreen mode for the game's window.
Parameters:
| Name | Description |
|---|---|
enabled | If the game's window should be in fullscreen mode. |
toggleFullscreen()
Toggles fullscreen mode on or off, depending on the current state.
toggleAutoPause()
Toggles auto-pause on or off.
Returns: The new value of auto-pause after toggling.
dispose()
See Also: .destroy
addGlobalShader(FlixelShader)
Adds a shader to the global post-processing chain applied to all game cameras together.
Unlike per-camera shaders (see FlixelCamera.setShader(FlixelShader)), a global shader captures the combined output of every game camera into a single full-screen framebuffer and applies the effect in one pass. This means barrel distortion, scanlines, and similar effects align correctly across camera boundaries. The global overlay (debug FPS display, etc.) is drawn after the global composite and is always excluded.
Shaders added with this method run in insertion order. When more than one shader is present they chain via ping-pong framebuffers so each pass feeds the next without re-rendering the scene.
Performance note: Every global shader adds a full-screen framebuffer pass per frame. On weaker or integrated-graphics hardware this can have a meaningful impact on frame budget. It is strongly recommended to expose a graphics settings option in your game so players can disable shader effects. A common pattern is to call FlixelGame.removeGlobalShader(FlixelShader) and camera.setShader(null) when the player turns shaders off, and re-add them when turned back on.
Adding the same shader instance more than once is a no-op.
Parameters:
| Name | Description |
|---|---|
shader | The shader to append to the global chain. |
removeGlobalShader(FlixelShader)
Removes a shader from the global post-processing chain.
If the chain becomes empty as a result, the scene framebuffers are released immediately. Removing a shader that was never added is a no-op.
Parameters:
| Name | Description |
|---|---|
shader | The shader to remove. |
Returns: true if the shader was found and removed, false otherwise.
destroy()
Destroys the game and all of its resources.
Note that this doesn't close the game entirely, it just disposes of the game's resources. If you want to close the entire game, use libGDX's Application.exit().
configureCrashHandler()
Configures the framework's crash handler to safely catch uncaught exceptions and gracefully close the game.
resetCameras()
Resets the camera list to contain a single default camera with the current window size as its viewport.
add(IFlixelBasic)
Adds a member to the global overlay group so it is updated and drawn on top of all game cameras while the overlay is enabled.
The overlay must be enabled via FlixelGame.enableGlobalOverlay(boolean) or FlixelGame.toggleGlobalOverlay() for added members to actually appear. This is safe to call even when the overlay is disabled.
Example usage:
fpsCounter = new FlixelText();
add(fpsCounter);
enableGlobalOverlay(true);
Parameters:
| Name | Description |
|---|---|
basic | The object to add to the overlay group. |
remove(IFlixelBasic)
Removes a member from the global overlay group.
Parameters:
| Name | Description |
|---|---|
basic | The object to remove from the overlay group. |
enableGlobalOverlay(boolean)
Enables or disables the global overlay. When disabled, the overlay group is neither updated nor drawn, making it zero-cost on the frame budget.
Parameters:
| Name | Description |
|---|---|
enabled | Whether the overlay should be active. |
toggleGlobalOverlay()
Toggles the global overlay on if it is currently off, and off if it is currently on.
Returns: The new enabled state after toggling.
getCameras()
getBatch()
getCompositeBatch()
getFrameRenderCalls()
Returns the total number of FlixelBatch render calls issued during the most recently completed frame, summed across all camera passes. This value is not reset by intermediate begin/end cycles, so it correctly reflects the full per-frame cost when multiple cameras are active.
Returns: Per-frame render call count from the last completed draw pass.
getBgColor()
setBgColor(Color)
isTransparentFramebufferRequested()
getTransparentFramebufferRequested()
Returns whether an alpha-capable framebuffer was requested at launch.
isTransparencyActive()
Returns: true after FlixelGame.applyBackdropForDesktopTransparency(boolean) was called with true.
getTransparencyActive()
Returns true after desktop transparency was applied via FlixelGame.applyBackdropForDesktopTransparency(boolean).
applyBackdropForDesktopTransparency(boolean)
Updates global and per-camera backdrop drawing for desktop compositing. Called from FlixelWindow. When desktop see-through is off but the GLFW window was created with a transparent-capable framebuffer, FlixelDrawable.draw(FlixelBatch) also forces framebuffer alpha to 1 after rendering so tinted sprites do not composite through the real desktop.
Parameters:
| Name | Description |
|---|---|
active | true for transparent clears and camera fills. false restores colors captured the first time transparency was enabled this session (then clears that cache), or opaque black if transparency was never enabled. |
getTitle()
isGamePaused()
getGamePaused()
Returns whether the game is currently paused.
isClosing()
getClosing()
Returns whether the game is in the process of closing.
isClosed()
getClosed()
Returns whether the game window has fully closed.
getFramerate()
isVsync()
getVsync()
isFullscreen()
getFullscreen()
getInitialWidth()
getInitialHeight()
isGlobalOverlayEnabled()
getGlobalOverlayEnabled()
Returns whether the global overlay camera is enabled.
getOverlayCamera()
Returns the private FlixelCamera used to render the global overlay.
This camera is never registered in Flixel.cameras, so it is not affected by state code or camera resets. Its scroll is always zero, which means overlay members placed at position (x, y) always appear at those same design-resolution coordinates regardless of what the active game camera is doing.
Returns: The overlay camera, or null if FlixelGame.create() has not yet run.
getOverlayGroup()
Returns the FlixelBasicGroup that holds all members added via FlixelGame.add(IFlixelBasic).
Returns: The overlay group, or null if FlixelGame.create() has not yet run.