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 |
Members
canvas
Get the current drawing canvas
ctx
Get the current drawing context
deltaTime
Get the current framerate as milliseconds per frame (mspf)
deltaTime
Set the framerate as milliseconds per frame (mspf)
frameCount
Get the count of frames since the start
frameRate
Get the current framerate as frames per second (fps)
frameRate
Set a framerate
height
Get the drawing area height
is_recording
Get the current recording state
(readonly) mousePosition
Get the current mouse position
(readonly) prevMousePosition
Get the previous mouse position
recording
Get the the current recording state
width
Get the drawing area width
Methods
background(color)
Set the background color for the canvas
Parameters:
Name | Type | Description |
---|---|---|
color |
string | number |
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 |
draw()
Main sketch function, will be run continuously
keyDown(key, code)
Public callback for key down
Parameters:
Name | Type | Description |
---|---|---|
key |
string | |
code |
number |
keyPress(key, code)
Public callback for key press
Parameters:
Name | Type | Description |
---|---|---|
key |
string | |
code |
number |
keyUp(key, code)
Public callback for key up
Parameters:
Name | Type | Description |
---|---|---|
key |
string | |
code |
number |
loop()
Starts looping the script
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 |
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 |
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 |
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 |
noLoop()
Stops looping the script
preload()
Function ran once, before the sketch is actually loaded
saveFrame(titleopt)
Save current frame
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
title |
string |
<optional> |
null | The image filename (optional). |
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 |
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 |
setup()
Function ran once
startRecording()
Start recording frames
stopRecording()
Stop recording frames