DebugToggle

Steps through a cycle of debug overlays each time a button (or ControlMap action) is pressed, wrapping back to the first. Made by Game.enableDebugToggle(); nothing is bound until a game calls that.

It acts on presses before entities get them and doesn't consume them, so pick a button gameplay doesn't use, or turn enabled off while it does. It still works while the game is paused, but not in a frame a UI widget captured input (GameInput.consume()).

Each change posts a "debugLevelChanged" game event ({level, previousLevel}). Subclass to change how a level is applied (applyLevel()) or what happens after (onLevelChanged()), and assign the instance to game.debugToggle.

Properties

  • button (string) — Remote button that steps the cycle (used when action isn't bound)
  • action (string) — ControlMap action that steps the cycle, when bound
  • enabled (boolean) — Does the button do anything?
  • game (BGE.Game)
  • levels (Array.<BGE.Debug.DebugLevel>)
  • level (integer)
  • managedFlags (roAssociativeArray) — Flags any level sets - the only ones applyLevel() touches

Example

CODE
game.enableStandardDebugUi()
game.enableDebugToggle({levels: [{}, {showUi: true, colliders: true}]})

Constructor

new DebugToggle( game: BGE.Game, options?: BGE.Debug.DebugToggleOptions, ): DebugToggle

Parameters

  • game (BGE.Game)
  • options (BGE.Debug.DebugToggleOptions, optional, default: "{}")

Instance Methods

setLevels(levels: Array.<BGE.Debug.DebugLevel>): void

Replaces the cycle. Keeps the current index (wrapped to fit) without applying anything.

Parameters

  • levels (Array.<BGE.Debug.DebugLevel>)

Returns

  • void

getLevel(): integer

Index of the current level

Returns

  • integer

getLevelCount(): integer

How many levels the cycle has

Returns

  • integer

nextLevel(): integer

Steps to the next level, wrapping back to the first.

Returns

  • integer — the new level's index

setLevel(index: integer): void

Applies a level (wrapped into range) and posts "debugLevelChanged".

Parameters

  • index (integer)

Returns

  • void

handleInput(input: BGE.GameInput): boolean

Steps the cycle if this input is a press of button (and no action is in use). Game calls this for each of the frame's inputs.

Parameters

Returns

  • boolean — true if it stepped

handleControls(): boolean

Steps the cycle if action is bound and was pressed this frame. Game calls this once a frame.

Returns

  • boolean — true if it stepped

applyLevel(settings: BGE.Debug.DebugLevel): void

protected

Parameters

  • settings (BGE.Debug.DebugLevel)

Returns

  • void

onLevelChanged(level: integer, previousLevel: integer): void

protected

Parameters

  • level (integer)
  • previousLevel (integer)

Returns

  • void

defaultLevels(): Array.<BGE.Debug.DebugLevel>

protected

Returns

  • Array.<BGE.Debug.DebugLevel>