Class: Engine

Engine(canvas, ctx, fpsopt)

Class containing the main engine running a canvas

Constructor

new Engine(canvas, ctx, fpsopt)

Create the engine controlling a canvas
Parameters:
Name Type Attributes Default Description
canvas Object DOM element containing the canvas
ctx Object Drawing context of the canvas
fps number <optional>
60 Frames per second
Source:

Members

canvas

Get the current drawing canvas
Source:

ctx

Get the current drawing context
Source:

deltaTime

Get the current framerate as milliseconds per frame (mspf)
Source:

deltaTime

Set the framerate as milliseconds per frame (mspf)
Source:

frameCount

Get the count of frames since the start
Source:

frameRate

Get the current framerate as frames per second (fps)
Source:

frameRate

Set a framerate
Source:

height

Get the drawing area height
Source:

is_recording

Get the current recording state
Source:

(readonly) mousePosition

Get the current mouse position
Source:

(readonly) prevMousePosition

Get the previous mouse position
Source:

recording

Get the the current recording state
Source:

width

Get the drawing area width
Source:

Methods

background(color)

Set the background color for the canvas
Parameters:
Name Type Description
color string | number
Source:

click(x, y)

Public callback for mouse click and touchscreen tap
Parameters:
Name Type Description
x number coordinate of the click/tap location
y number coordinate of the click/tap location
Source:

draw()

Main sketch function, will be run continuously
Source:

keyDown(key, code)

Public callback for key down
Parameters:
Name Type Description
key string
code number
Source:

keyPress(key, code)

Public callback for key press
Parameters:
Name Type Description
key string
code number
Source:

keyUp(key, code)

Public callback for key up
Parameters:
Name Type Description
key string
code number
Source:

loop()

Starts looping the script
Source:

mouseDown(x, y)

Public callback for mouse and touchscreen pressed
Parameters:
Name Type Description
x number coordinate of the click/tap location
y number coordinate of the click/tap location
Source:

mouseDragged(x, y)

Public callback for mouse and touchscreen drag
Parameters:
Name Type Description
x number coordinate of the click/tap location
y number coordinate of the click/tap location
Source:

mouseMoved(x, y)

Public callback for mouse and touchscreen moved
Parameters:
Name Type Description
x number coordinate of the click/tap location
y number coordinate of the click/tap location
Source:

mouseUp(x, y)

Public callback for mouse and touchscreen up
Parameters:
Name Type Description
x number coordinate of the click/tap location
y number coordinate of the click/tap location
Source:

noLoop()

Stops looping the script
Source:

preload()

Function ran once, before the sketch is actually loaded
Source:

saveFrame(titleopt)

Save current frame
Parameters:
Name Type Attributes Default Description
title string <optional>
null The image filename (optional).
Source:

saveRecording(filename)

Save the recording as a series of frames in a zip file
Parameters:
Name Type Default Description
filename str frames.zip of the file to download
Source:

scaleFromCenter(x, yopt)

Scale the canvas by a factor from the center. If only one parameter is passed, the canvas will be scaled uniformly.
Parameters:
Name Type Attributes Default Description
x number
y number <optional>
null
Source:

setup()

Function ran once
Source:

startRecording()

Start recording frames
Source:

stopRecording()

Stop recording frames
Source: