Debug

LittleJS Debug System

  • Press Esc to show debug overlay with mouse pick
  • Number keys toggle debug functions
  • +/- apply time scale
  • Debug primitive rendering
  • Save a 2d canvas as a png image

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) 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) showWatermark :boolean

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

Type:
  • boolean
Default Value
  • true

Methods

(static) ASSERT(assert, …outputopt)

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

Parameters:
NameTypeAttributesDescription
assertboolean
outputObject<optional>
<repeatable>

error message output

(static) LOG(…outputopt)

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

Parameters:
NameTypeAttributesDescription
outputObject<optional>
<repeatable>

message output

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

Draw a debug circle in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizenumber<optional>
0

diameter

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

(static) debugClear()

Clear all debug primitives in the list

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

Draw a debug line in world space

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

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

Draw a debug combined axis aligned bounding box in world space

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

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

Draw a debug point in world space

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

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

Draw a debug poly in world space

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

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

Draw a debug rectangle in world space

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

(static) debugSaveCanvas(canvas, filenameopt, typeopt)

Save a canvas to disk

Parameters:
NameTypeAttributesDefaultDescription
canvasHTMLCanvasElement | OffscreenCanvas
filenamestring<optional>
screenshot
typestring<optional>
image/png

(static) debugSaveDataURL(dataURL, filename)

Save a data url to disk

Parameters:
NameTypeDescription
dataURLstring
filenamestring

(static) debugSaveText(text, filenameopt, typeopt)

Save a text file to disk

Parameters:
NameTypeAttributesDefaultDescription
textstring
filenamestring<optional>
text
typestring<optional>
text/plain

(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 a debug axis aligned bounding box in world space

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

(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) setShowWatermark(show)

Set if watermark with FPS should be shown

Parameters:
NameTypeDescription
showboolean