Skip to main content

A class for general debugging purposes in Voxelize, including FPS, value tracking, and real-time value testing.

Example

const debug = new VOXELIZE.Debug();

// Track the voxel property of `controls`.
debug.registerDisplay("Position", controls, "voxel");

// Add a function to track sunlight dynamically.
debug.registerDisplay("Sunlight", () => {
return world.getSunlightByVoxel(...controls.voxel);
});

// In the game loop, trigger debug updates.
debug.update();

Debug

Hierarchy

  • Group

    Debug

Constructors

constructor

new Debug(domElement?, options?): Debug

Create a new Debug instance.

Parameters

NameTypeDefault valueDescription
domElementHTMLElementdocument.bodyThe DOM element to append the debug panel to.
optionsPartial<DebugOptions>{}Parameters to create a Debug instance.

Returns

Debug

Overrides

Group.constructor

Properties

dataWrapper

dataWrapper: HTMLDivElement

The HTML element that wraps all the debug entries and stats.js instance, located on the top-left by default.


domElement

domElement: HTMLElement

The DOM element to append the debug panel to. Defaults to document.body.


entriesWrapper

entriesWrapper: HTMLDivElement

A HTML element wrapping all registered debug entries.


options

options: DebugOptions

Parameters to create a Debug instance.


stats

Optional stats: Stats

The stats.js instance, situated in the top-left corner after the data entries.

Methods

displayNewline

displayNewline(): this

Add an empty line to the debug entries for spacing.

Returns

this

The debug instance for chaining.


displayTitle

displayTitle(title): this

Add a static title to the debug entries for grouping.

Parameters

NameTypeDescription
titlestringA title to display.

Returns

this

The debug instance for chaining.


dispose

dispose(): void

Returns

void


registerDisplay

registerDisplay<T>(title, object?, attribute?, formatter?): this

Register a new object attribute to track. Needs to call Debug.update in the game loop to update the value.

Type parameters

NameType
Tany

Parameters

NameTypeDescription
titlestringThe title of the debug entry.
object?TThe object to track.
attribute?keyof TThe attribute of the object to track.
formatter(str: string) => stringA function to format the value of the attribute.

Returns

this

The debug instance for chaining.


removeDisplay

removeDisplay(title): void

Remove a registered object attribute from tracking.

Parameters

NameTypeDescription
titlestringThe title of the debug entry.

Returns

void


toggle

toggle(force?): void

Toggle the debug instance on/off.

Parameters

NameTypeDefault valueDescription
forceanynullWhether or not to force the debug panel to be shown/hidden.

Returns

void


update

update(): void

Update the debug entries with the latest values. This should be called in the game loop. Utilizes requestAnimationFrame to reduce lag spikes by not overloading the main thread.

Returns

void