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, constant) enableAsserts :boolean

True if asserts are enabled

Type:
  • boolean
Default Value
  • true

(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 not do anything in release builds

Parameters:
NameTypeAttributesDescription
assertboolean
outputObject<optional>
<repeatable>

error message output

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

Draw a debug circle in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizenumber<optional>
0

diameter

colorstring<optional>
#fff
timenumber<optional>
0
fillboolean<optional>
false

(static) debugClear()

Clear all debug primitives in the list

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

Draw a debug line in world space

Parameters:
NameTypeAttributesDefaultDescription
posAVector2
posBVector2
colorstring<optional>
widthnumber<optional>
0.1
timenumber<optional>

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

Draw a debug combined axis aligned bounding box in world space

Parameters:
NameTypeAttributesDescription
posAVector2
sizeAVector2
posBVector2
sizeBVector2
colorstring<optional>

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

Draw a debug point in world space

Parameters:
NameTypeAttributesDescription
posVector2
colorstring<optional>
timenumber<optional>
anglenumber<optional>

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

Draw a debug poly in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
pointsArray.<Vector2>
colorstring<optional>
#fff
timenumber<optional>
0
anglenumber<optional>
0
fillboolean<optional>
false

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

Draw a debug rectangle in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
Vector2()
colorstring<optional>
#fff
timenumber<optional>
0
anglenumber<optional>
0
fillboolean<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()

Show error as full page of red text

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

Draw a debug axis aligned bounding box in world space

Parameters:
NameTypeAttributesDefaultDescription
textstring
posVector2
sizenumber<optional>
1
colorstring<optional>
#fff
timenumber<optional>
0
anglenumber<optional>
0
fontstring<optional>
monospace

(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