Constructor
new Engine(canvas)
Create the engine controlling a canvas
Parameters:
| Name | Type | Description |
|---|---|---|
canvas |
object | DOM element containing the canvas |
Members
canvas
Get the current drawing canvas
ctx
Get the current drawing context
deltaTime
Get the current framerate as milliseconds per frame (mspf)
- Deprecated:
- This method is deprecated and will be removed in future versions. Use the delta_time property instead.
- Source:
deltaTimeAverage
Get the average framerate as milliseconds per frame (mspf)
- Deprecated:
- This method is deprecated and will be removed in future versions. Use the delta_time_average property instead.
- Source:
delta_time
Get the current framerate as milliseconds per frame (mspf)
delta_time_average
Get the average framerate as milliseconds per frame (mspf)
frameCount
Get the count of frames since the start
- Deprecated:
- This method is deprecated and will be removed in future versions. Use the frame_count property instead.
- Source:
frameRate
Get the current framerate as frames per second (fps)
- Deprecated:
- This method is deprecated and will be removed in future versions. Use the frame_rate property instead.
- Source:
frameRateAverage
Get the average framerate as frames per second (fps)
- Deprecated:
- This method is deprecated and will be removed in future versions. Use the frame_rate_average property instead.
- Source:
frame_count
Get the count of frames since the start
frame_rate
Get the current framerate as frames per second (fps)
frame_rate_average
Get the average framerate as frames per second (fps)
height
Get the drawing area height
height
Set the drawing area height
is_recording
Get the current recording state
mouseInside
Get whether the mouse is currently inside the canvas
- Deprecated:
- This method is deprecated and will be removed in future versions. Use the mouse_inside property instead.
- Source:
(readonly) mousePosition
Get the current mouse position
- Deprecated:
- This method is deprecated and will be removed in future versions. Use the mouse_position property instead.
- Source:
mouse_inside
Get whether the mouse is currently inside the canvas
(readonly) mouse_position
Get the current mouse position
(readonly) prevMousePosition
Get the previous mouse position
- Deprecated:
- This method is deprecated and will be removed in future versions. Use the prev_mouse_position property instead.
- Source:
(readonly) prev_mouse_position
Get the previous mouse position
width
Get the drawing area width
width
Set the drawing area width
Methods
background(color)
Set the background color for the canvas
Parameters:
| Name | Type | Description |
|---|---|---|
color |
string | number | Color can be a CSS< RGB, RGBA, HEX, HEAX, HSL, HSLA string, a Color object, or a monochrome value (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 |
clickHandler(e)
Handler for mouse click/touchscreen tap
Parameters:
| Name | Type | Description |
|---|---|---|
e |
MouseEvent | event |
draw(dt)
Main sketch function, will be run continuously unless noLoop() is called
Parameters:
| Name | Type | Description |
|---|---|---|
dt |
number | Delta time in milliseconds since last frame |
keyDown(key, code)
Public callback for key down
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | pressed key |
code |
number | code of the pressed key |
keyDownHandler(e)
Handler for key pressed event
Parameters:
| Name | Type | Description |
|---|---|---|
e |
KeyboardEvent | event |
keyPress(key, code)
Public callback for key press
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | pressed key |
code |
string | code of the pressed key |
keyPressHandler(e)
Handler for key press event
Parameters:
| Name | Type | Description |
|---|---|---|
e |
KeyboardEvent | event |
keyUp(key, code)
Public callback for key up
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | pressed key |
code |
number | code of the pressed key |
keyUpHandler(e)
Handler for key up event
Parameters:
| Name | Type | Description |
|---|---|---|
e |
KeyboardEvent | event |
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 |
mouseDownHandler(e)
Handler for mouse down
Parameters:
| Name | Type | Description |
|---|---|---|
e |
MouseEvent | event |
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 |
mouseEnter(x, y)
Public callback for mouse and touchscreen entered
Parameters:
| Name | Type | Description |
|---|---|---|
x |
number | coordinate of the click/tap location |
y |
number | coordinate of the click/tap location |
mouseEnterHandler(e)
Handler for move entered event
Parameters:
| Name | Type | Description |
|---|---|---|
e |
MouseEvent | event |
mouseLeave(x, y)
Public callback for mouse and touchscreen left
Parameters:
| Name | Type | Description |
|---|---|---|
x |
number | coordinate of the click/tap location |
y |
number | coordinate of the click/tap location |
mouseLeaveHandler(e)
Handler for move leave event
Parameters:
| Name | Type | Description |
|---|---|---|
e |
MouseEvent | event |
mouseMoveHandler(e)
Handler for moved mouse
Parameters:
| Name | Type | Description |
|---|---|---|
e |
MouseEvent | event |
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 |
mouseUpHandler(e)
Handler for mouse up
Parameters:
| Name | Type | Description |
|---|---|---|
e |
MouseEvent | event |
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 |
string | frames.zip | of the file to download |
scaleFromCenter(x, y)
Scale the canvas by a factor from the center.
If only one parameter is passed, the canvas will be scaled uniformly.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
x |
number | scaling factor in the x direction | |
y |
number | null | scaling factor in the y direction |
setup()
Function ran once
startRecording()
Start recording frames
stop()
Completely stop the engine.
Note that this step is final and there's no way to programatically restart it after this call.
stopRecording()
Stop recording frames