Skip to main content

FlixelDebugManager

View source

class

org.flixelgdx.debug.FlixelDebugManager

public class FlixelDebugManager

The single entry point for everything related to the FlixelGDX debugger.

An instance of this class is automatically created when Flixel.initialize(FlixelGame) runs and is exposed as the static field Flixel.debug, mirroring how Flixel.sound, Flixel.assets, and friends work. From your game code you can do things like:

Flixel.debug.toggleVisible();
Flixel.debug.setDrawDebug(true);
Flixel.debug.registerCommand("hello", args -> Flixel.info("Hi!"));
Flixel.debug.executeCommand("hello");

// Customize keybinds via the overlay field (null-safe: only set after debug mode starts).
if (Flixel.debug.overlay != null) {
Flixel.debug.overlay.toggleKey = FlixelKey.F1;
}

The manager is intentionally lightweight: it forwards visibility/hitbox toggles to the active FlixelDebugOverlay, owns the registry of console commands, and tracks the "currently inspected sprite" for the texture inspector window. The overlay itself (and the platform-specific UI) reads from the manager rather than the other way around so the manager can stay platform-agnostic and reflection-free.

Custom commands

Use FlixelDebugManager.registerCommand(String, Consumer<FlixelDebugCommandArgs>) with a handler that receives FlixelDebugCommandArgs. That keeps parsing explicit and avoids reflection, which is important on platforms where reflection is restricted (TeaVM, R8/ProGuard-shrunk Android builds).

Thread safety

All public methods are intended to be called from the libGDX main thread. Reading the registered commands map outside the main thread is unsupported.

Constructors

FlixelDebugManager()

public FlixelDebugManager()

Internal: registers the small set of always-available commands (help, clear, etc.).


Fields

MAX_HISTORY_ENTRIES

public static final int MAX_HISTORY_ENTRIES = 64

Maximum entries kept in the input history (oldest are dropped first).


overlay

public FlixelDebugOverlay overlay

The active debug overlay. Defaults to FlixelNoopDebugOverlay.INSTANCE so this field is never null, meaning callers do not need a null check. When debug mode starts, Flixel replaces this with a real overlay instance.

Access keybinds and visibility via this field:

Flixel.debug.overlay.toggleKey = FlixelKey.F1;
Flixel.debug.overlay.setVisible(true);

Methods

isVisible()

public boolean isVisible()

Returns true when the overlay is on screen.


setVisible(boolean)

public void setVisible(boolean visible)

Shows or hides the overlay.

Parameters:

NameDescription
visibletrue to show, false to hide.

toggleVisible()

public void toggleVisible()

Toggles the overlay visibility.


isDrawDebug()

public boolean isDrawDebug()

Returns true when bounding-box drawing (hitboxes) is on.


setDrawDebug(boolean)

public void setDrawDebug(boolean drawDebug)

Sets whether bounding boxes (hitboxes) should be drawn.

Parameters:

NameDescription
drawDebugtrue to draw, false to hide.

toggleDrawDebug()

public void toggleDrawDebug()

Toggles bounding-box drawing.


setInspectedSprite(FlixelObject)

public void setInspectedSprite(FlixelObject obj)

Sets the sprite currently inspected by the texture inspector window. Pass null to clear the selection.

Parameters:

NameDescription
objThe sprite to inspect, or null to clear.

getInspectedSprite()

public FlixelObject getInspectedSprite()

Returns the sprite currently inspected, or null if no sprite is selected (or the previously selected sprite has been destroyed). The returned sprite may be of any subclass of FlixelObject.

Returns: The inspected sprite, or null.


getDraggedSprite()

public FlixelObject getDraggedSprite()

Returns the sprite that is currently being dragged via the LMB picker, or null.


trackBatch(FlixelBatch)

public void trackBatch(FlixelBatch batch)

Registers a FlixelBatch whose FlixelBatch.getRenderCalls() will be included in the debugger's total render-call count shown in the Stats panel. The framework's own batch is already counted automatically; call this for any additional batches your game creates.

Registering a batch that is already tracked is a no-op. The batch must remain valid (not disposed) for as long as it is registered. Call FlixelDebugManager.untrackBatch(FlixelBatch) before disposing a tracked batch.

Example:

FlixelBatch uiBatch = new FlixelSpriteBatch();
Flixel.debug.trackBatch(uiBatch);

Parameters:

NameDescription
batchThe batch to track. Must not be null.

untrackBatch(FlixelBatch)

public void untrackBatch(FlixelBatch batch)

Removes a batch that was previously registered via FlixelDebugManager.trackBatch(FlixelBatch). Passing a batch that was never registered is a no-op.

Parameters:

NameDescription
batchThe batch to stop tracking.

getTrackedBatches()

public Array<FlixelBatch> getTrackedBatches()

addTrackerEntry(FlixelDebugTrackerEntry)

public void addTrackerEntry(FlixelDebugTrackerEntry entry)

Registers a FlixelDebugTrackerEntry whose label -> value pairs are shown as a named, collapsible group in the overlay's Tracker panel. Registering the same entry twice is a no-op.

Example:

Flixel.debug.addTrackerEntry(new EnemyTrackerEntry(enemyManager));

Parameters:

NameDescription
entryThe entry to register. Must not be null.

removeTrackerEntry(FlixelDebugTrackerEntry)

public void removeTrackerEntry(FlixelDebugTrackerEntry entry)

Removes a previously registered tracker entry. Passing an entry that was never registered is a no-op.

Parameters:

NameDescription
entryThe entry to stop tracking.

registerCommand(String, Consumer<FlixelDebugCommandArgs>)

public void registerCommand(String name, Consumer<FlixelDebugCommandArgs> handler)

Registers a console command. The handler receives a FlixelDebugCommandArgs object that wraps the positional tokens the user typed after the command name.

Example:

Flixel.debug.registerCommand("hello", args -> {
String name = args.getString(0, "World"); // 0 = The first argument after the command name.
Flixel.info("Hello, " + name + "!");
});

Parameters:

NameDescription
nameThe command name (the first token typed in the console).
handlerThe handler invoked when the command runs.

unregisterCommand(String)

public void unregisterCommand(String name)

Removes a previously registered command.

Parameters:

NameDescription
nameThe command name to remove.

executeCommand(String)

public boolean executeCommand(String commandLine)

Executes a raw command line. The first whitespace-separated token is the command name and any remaining tokens become positional arguments. Logs an error to Flixel.log if the command does not exist.

Parameters:

NameDescription
commandLineThe raw input line (for example "spawn enemy.png 1.5").

Returns: true if a command matched and was executed; false otherwise.


getCommandHistory()

public Array<String> getCommandHistory()

Returns the in-memory command history (oldest first). The returned array is the live backing store and must not be modified. Use Array.size and indexed access to read it.

Returns: The command history (live, do not modify).


getRegisteredCommandNames()

public Array<String> getRegisteredCommandNames()

Returns the Array of registered command names. The returned array is freshly allocated.


hasCommand(String)

public boolean hasCommand(String name)

Returns true if a command with the given name is registered.