Creates a new canvas, sets up mouse and keyboard events, and provides an animation frame loop. All rendering and events are delegated to the provided scene object.
container
: An HTML element IDscene
: Object providing options and implementing event handlers
Upon initialization, the following callbacks will be called immediately:
init()
render()
options
:width
: Canvas width (default to container's width)height
: Canvas height (default to container's height)
init(props)
: Called on initializationrender(props)
: Called on each animation frameresize(props)
: Called on resize eventkeyDown(props)
: Called on keyDown eventkeyUp(props)
: Called on keyUp eventmouseDown(props)
: Called on mouseDown eventmouseUp(props)
: Called on mouseUp eventmouseMove(props)
: Called on mouseMove eventmouseWheel(props)
: Called on mouseWheel event
scene
: Thescene
object provided towithCanvas
container
: Container HTML elementcanvas
: Canvas HTML elementcontext
: 2D rendering context forcanvas
draw()
: Trigger a call toscene.render
start()
: Start the animation frame loopstop()
: Stop the animation frame looprunning
: True while the animation loop is runningtime
: Current time in millisecondsdelta
: Milliseconds since last frameevent
: Browser event. Included for resize, keyDown/Up and mouseDown/Up/Move/wheel callbacksconstrain(value, min, max)
: Clip a value to a rangemap(value, inMin, inMax, outMin, outMax)
: Map a value from one range to another