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
- Source
Members
(static, constant) debug :boolean
True if debug is enabled
- boolean
- Default Value
- true
- Source
(static) debugKey :string
Key code used to toggle debug mode, Esc by default
- string
- Default Value
- Escape
- Source
(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
- boolean
- Source
(static) debugOverlay :boolean
True if the debug overlay is active, always false in release builds
- boolean
- Source
(static, constant) debugPointSize :number
Size to render debug points by default
- number
- Default Value
- 0.5
- Source
(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
- boolean
- Source
(static) debugWatermark :boolean
True if watermark with FPS should be shown, false in release builds
- boolean
- Default Value
- true
- Source
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
| Name | Type | Attributes | Description |
|---|---|---|---|
assert | * | any value, the assert fails when it is falsy | |
output | Object | <repeatable> | error message output |
- Source
(static) LOG(…output)
Log to console if debug is enabled, does nothing in release builds
| Name | Type | Attributes | Description |
|---|---|---|---|
output | Object | <repeatable> | message output |
- Source
(static) debugCircle(pos, sizeopt, coloropt, timeopt, fillopt, screenSpaceopt)
Draw a debug circle in world space, or on the screen with screenSpace
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | |||
size | number | <optional> | 0 | diameter |
color | Color | | <optional> | ||
time | number | <optional> | 0 | |
fill | boolean | <optional> | false | |
screenSpace | boolean | <optional> | drawScreenSpace |
- Source
(static) debugClear()
Clear all debug primitives in the list
- Source
(static) debugLine(posA, posB, coloropt, widthopt, timeopt, screenSpaceopt)
Draw a debug line in world space, or on the screen with screenSpace
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
posA | Vector2 | |||
posB | Vector2 | |||
color | Color | | <optional> | ||
width | number | <optional> | 0.1 | |
time | number | <optional> | 0 | |
screenSpace | boolean | <optional> | drawScreenSpace |
- Source
(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
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
posA | Vector2 | |||
sizeA | Vector2 | |||
posB | Vector2 | |||
sizeB | Vector2 | |||
color | Color | | <optional> | ||
time | number | <optional> | ||
screenSpace | boolean | <optional> | drawScreenSpace |
- Source
(static) debugPoint(pos, coloropt, timeopt, angleopt, screenSpaceopt)
Draw a debug point in world space, or on the screen with screenSpace
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | |||
color | Color | | <optional> | ||
time | number | <optional> | ||
angle | number | <optional> | ||
screenSpace | boolean | <optional> | drawScreenSpace |
- Source
(static) debugPoly(pos, points, coloropt, timeopt, angleopt, fillopt, screenSpaceopt)
Draw a debug poly in world space, or on the screen with screenSpace
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | |||
points | Array.<Vector2> | |||
color | Color | | <optional> | ||
time | number | <optional> | 0 | |
angle | number | <optional> | 0 | |
fill | boolean | <optional> | false | |
screenSpace | boolean | <optional> | drawScreenSpace |
- Source
(static) debugRect(pos, sizeopt, coloropt, timeopt, angleopt, fillopt, screenSpaceopt)
Draw a debug rectangle in world space, or on the screen with screenSpace
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | |||
size | Vector2 | <optional> | vec2(0) | |
color | Color | | <optional> | ||
time | number | <optional> | 0 | |
angle | number | <optional> | 0 | |
fill | boolean | <optional> | false | |
screenSpace | boolean | <optional> | drawScreenSpace |
- Source
(static) debugScreenshot()
Trigger debug system to take a screenshot
- Source
(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
- Source
(static) debugText(text, pos, sizeopt, coloropt, timeopt, angleopt, fontopt, screenSpaceopt)
Draw debug text in world space, or on the screen with screenSpace
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
text | string | | |||
pos | Vector2 | |||
size | number | <optional> | 1 | |
color | Color | | <optional> | ||
time | number | <optional> | 0 | |
angle | number | <optional> | 0 | |
font | string | <optional> | monospace | |
screenSpace | boolean | <optional> | drawScreenSpace |
- Source
(static) debugVideoCaptureIsActive()
Check if video capture is active
- Source
(static) debugVideoCaptureStart()
Start capturing video
- Source
(static) debugVideoCaptureStop()
Stop capturing video and save to disk
- Source
(static) setDebugKey(key)
Set key code used to toggle debug mode, Esc by default
| Name | Type | Description |
|---|---|---|
key | string |
- Source
(static) setDebugKeysAlways(enableopt)
Set if the debug keys work while the overlay is closed, the number keys and the +/- time keys
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
enable | boolean | <optional> | true |
- Source
(static) setDebugOverlay(showopt)
Open or close the debug overlay from code, as the debug key does; does nothing in release builds
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
show | boolean | <optional> | true |
- Source
(static) setDebugTweakables(showopt)
Set if the tweakables panel is shown, as 9 does while the debug overlay is open
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
show | boolean | <optional> | true |
- Source
(static) setDebugWatermark(show)
Set if watermark with FPS should be shown
| Name | Type | Description |
|---|---|---|
show | boolean |
- Source