Debug

LittleJS Debug System

  • Press Esc to toggle debug overlay with object picking
  • Number keys toggle debug visualizations (physics, particles, etc.) while the overlay is open
  • +/- keys control time scale for slow motion/fast forward while the overlay is open
  • setDebugKeysAlways lets those keys work with the overlay closed too
  • ASSERT and LOG macros for development (removed in release builds)
  • Debug primitive rendering (rectangles, circles, lines, points, text)
  • Screenshot and video capture support
  • FPS counter and performance watermark
  • Debug overlay shows mouse position and picked objects

Members

(static, constant) debug :boolean

True if debug is enabled

Type:
  • boolean
Default Value
  • true

(static) debugKey :string

Key code used to toggle debug mode, Esc by default

Type:
  • string
Default Value
  • Escape

(static) debugKeysAlways :boolean

Let the debug keys work while the overlay is closed, the number keys and the +/- time keys, for a game that does not use them; off by default, so they only work while the overlay is open

Type:
  • boolean

(static) debugOverlay :boolean

True if the debug overlay is active, always false in release builds

Type:
  • boolean

(static, constant) debugPointSize :number

Size to render debug points by default

Type:
  • number
Default Value
  • 0.5

(static) debugTweakables :boolean

True if the tweakables panel is shown, 9 toggles it while the overlay is open; set it to show the panel from the start, the panel is never shown in release builds

Type:
  • boolean

(static) debugWatermark :boolean

True if watermark with FPS should be shown, false in release builds

Type:
  • boolean
Default Value
  • true

Methods

(static) ASSERT(assert, …output)

Asserts if the expression is false, does nothing in release builds Halts execution if the assert fails and throws an error

Parameters:
NameTypeAttributesDescription
assert*

any value, the assert fails when it is falsy

outputObject<repeatable>

error message output

(static) LOG(…output)

Log to console if debug is enabled, does nothing in release builds

Parameters:
NameTypeAttributesDescription
outputObject<repeatable>

message output

(static) debugCircle(pos, sizeopt, coloropt, timeopt, fillopt, screenSpaceopt)

Draw a debug circle in world space, or on the screen with screenSpace

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizenumber<optional>
0

diameter

colorColor | string<optional>
timenumber<optional>
0
fillboolean<optional>
false
screenSpaceboolean<optional>
drawScreenSpace

(static) debugClear()

Clear all debug primitives in the list

(static) debugLine(posA, posB, coloropt, widthopt, timeopt, screenSpaceopt)

Draw a debug line in world space, or on the screen with screenSpace

Parameters:
NameTypeAttributesDefaultDescription
posAVector2
posBVector2
colorColor | string<optional>
widthnumber<optional>
0.1
timenumber<optional>
0
screenSpaceboolean<optional>
drawScreenSpace

(static) debugOverlap(posA, sizeA, posB, sizeB, coloropt, timeopt, screenSpaceopt)

Draw a debug combined axis aligned bounding box in world space, or on the screen with screenSpace

Parameters:
NameTypeAttributesDefaultDescription
posAVector2
sizeAVector2
posBVector2
sizeBVector2
colorColor | string<optional>
timenumber<optional>
screenSpaceboolean<optional>
drawScreenSpace

(static) debugPoint(pos, coloropt, timeopt, angleopt, screenSpaceopt)

Draw a debug point in world space, or on the screen with screenSpace

Parameters:
NameTypeAttributesDefaultDescription
posVector2
colorColor | string<optional>
timenumber<optional>
anglenumber<optional>
screenSpaceboolean<optional>
drawScreenSpace

(static) debugPoly(pos, points, coloropt, timeopt, angleopt, fillopt, screenSpaceopt)

Draw a debug poly in world space, or on the screen with screenSpace

Parameters:
NameTypeAttributesDefaultDescription
posVector2
pointsArray.<Vector2>
colorColor | string<optional>
timenumber<optional>
0
anglenumber<optional>
0
fillboolean<optional>
false
screenSpaceboolean<optional>
drawScreenSpace

(static) debugRect(pos, sizeopt, coloropt, timeopt, angleopt, fillopt, screenSpaceopt)

Draw a debug rectangle in world space, or on the screen with screenSpace

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
vec2(0)
colorColor | string<optional>
timenumber<optional>
0
anglenumber<optional>
0
fillboolean<optional>
false
screenSpaceboolean<optional>
drawScreenSpace

(static) debugScreenshot()

Trigger debug system to take a screenshot

(static) debugShowErrors()

Breaks on all asserts/errors, hides the canvas, and shows message in plain text This is a good function to call at the start of your game to catch all errors In release builds this function has no effect

(static) debugText(text, pos, sizeopt, coloropt, timeopt, angleopt, fontopt, screenSpaceopt)

Draw debug text in world space, or on the screen with screenSpace

Parameters:
NameTypeAttributesDefaultDescription
textstring | number
posVector2
sizenumber<optional>
1
colorColor | string<optional>
timenumber<optional>
0
anglenumber<optional>
0
fontstring<optional>
monospace
screenSpaceboolean<optional>
drawScreenSpace

(static) debugVideoCaptureIsActive()

Check if video capture is active

(static) debugVideoCaptureStart()

Start capturing video

(static) debugVideoCaptureStop()

Stop capturing video and save to disk

(static) setDebugKey(key)

Set key code used to toggle debug mode, Esc by default

Parameters:
NameTypeDescription
keystring

(static) setDebugKeysAlways(enableopt)

Set if the debug keys work while the overlay is closed, the number keys and the +/- time keys

Parameters:
NameTypeAttributesDefaultDescription
enableboolean<optional>
true

(static) setDebugOverlay(showopt)

Open or close the debug overlay from code, as the debug key does; does nothing in release builds

Parameters:
NameTypeAttributesDefaultDescription
showboolean<optional>
true

(static) setDebugTweakables(showopt)

Set if the tweakables panel is shown, as 9 does while the debug overlay is open

Parameters:
NameTypeAttributesDefaultDescription
showboolean<optional>
true

(static) setDebugWatermark(show)

Set if watermark with FPS should be shown

Parameters:
NameTypeDescription
showboolean