1 Events
lgc edited this page 2024-08-15 01:52:34 +00:00

Global Events

Init

function init() {
    // Your Code
}

Is called as soon as the browser page is prepared, exactly one frame before the first tick() execution.

Tick

function tick() {
    // Your Code
}

Is called on every "render tick". Interval is defined using the FPS configuration variable. Time between ticks = 1000/FPS ms.

When PAUSED is set to true execution of this function is paused until PAUSED is set back to false.

Mouse Events

On Mouse Move

function onMouseMove(x, y) {
    // Your Code
}

Is called whenever a mousemove event is recieved somewhere on the page, not limited to the canvas.

xand y contain the coordinates of the mouse pointer, relative to the position of the canvas (x = 0, y = 0 being top left).

Mouse Button Events

function onMouseDown(x, y, button) {
    // Your Code
}

function onMouseUp(x, y, button) {
    // Your Code
}

Are called whenever a mousedown or mouseup event, respectively, is recieved in the document. x and y are the coordinates of the mouse pointer, relative to the position of the canvas. button contains an integer between and including 0 and 2, defining the mouse button that was clicked or released (0 = Left Mouse Button, 1 = Middle Mouse Button, 2 = Right Mouse Button)

Touch Support

All Mouse Events also work using touchscreen devices. A touch is always treated as a Left Mouse Button (button = 0).

Multitouch is not supported.

Key Events

function onKeyDown(e) {
    // Your Code
}

function onKeyUp(e) {
    // Your Code
}

Are called whenever a keydown or keyup event, respectively, is recieved in the document. e is the event, the way it is passed from the document event handler.