Class: Scene

core~Scene()

Base Class for scenes that holds game objects and renders them.

Extends

Members

active :boolean

Wether or not this scene is the active scene and it is being rendered. Best not to set directly. Use engine.switchScene instead.
Type:
  • boolean
Default Value:
  • false
Source:

assets :module:core~Assets

A reference to the global Assets plugin.
Type:
Source:

camera :module:core~Camera

The camera object that belongs to this scene.
Type:
Source:

children :Array.<module:gameobjects~GameObject>

The children that are added to the scene. Children will be rendered on top of each other. So a child with a lower index will be behind children with a higher index.
Type:
Source:

engine :module:core~Engine

A reference to the main engine.
Type:
Source:

listeners :object

A dictionary of the event callbacks attached to this object.
Type:
  • object
Overrides:
Source:

name :string

The name you gave this instance of the scene in the game config.
Type:
  • string
Source:

options :object

An object that is taken from the game config and passed to a specific scene that was instantiated by the Engine. This way you can use the same scene class, but have multiple instances with different things going on. Available in the init function of the scene, but not in the constructor.
Type:
  • object
Source:

plugins :Array.<module:core~ScenePlugin>

An array that holds the scene plugins.
Type:
Source:

viewport :object

Information about the actual size of the viewport and canvas.
Type:
  • object
Properties:
Name Type Description
width number The actual width of the viewport or canvas. Not the one set in the game config.
height number The actual height of the viewport or canvas. Not the one set in the game config.
zoom number The actual zoom. Not the one set in the game config.
Source:

Methods

add(child) → {module:gameobjects~GameObject}

Adds a child to this scene.
Parameters:
Name Type Description
child module:gameobjects~GameObject The GameObject instance to be added.
Source:
Returns:
- Returns the child again.
Type
module:gameobjects~GameObject

emit(type, eopt)

Emits the event of a certain type and executes all callbacks.
Parameters:
Name Type Attributes Description
type string The name of the event it emits.
e object <optional>
An optional object that will be passed to the callbacks first argument.
Overrides:
Source:

(abstract) init()

Automatically called when the scene starts again. Can be used in your own Scene classes to setup the scene. No need to call `super.init()`.
Source:

off(typeopt, callbackopt)

Removes listeners from this object.
Parameters:
Name Type Attributes Description
type string <optional>
The name of the event to remove callback(s) for. If left empty, it will remove every single callback from this object.
callback function <optional>
The callback to remove. If left empty, it will remove all callbacks for the given type or when the type is empty every single callback on this object.
Overrides:
Source:

on(type, callback)

Continually listen on this object for an event.
Parameters:
Name Type Description
type string The name of the event.
callback function The function to execute each time the event is emitted.
Overrides:
Source:

once(type, callback)

Listen on this object for an event, but execute the callback only once.
Parameters:
Name Type Description
type string The name of the event.
callback function The function to execute once.
Overrides:
Source:

remove(child)

Removes a child from this scene. If the child has a body, the body will be removed from the world.
Parameters:
Name Type Description
child module:gameobjects~GameObject The GameObject to be removed.
Source:

render(context, time, delta)

Internal function. Automatically called every frame. Can be overriden, but it is best to call `super.render(context, time, delta)`. Using `update` is the preferred way to go to game logic.
Parameters:
Name Type Description
context CanvasRenderingContext2D The canvas render context.
time number The total time (in milliesconds) since the start of the game.
delta number The time elapsed (in milliseconds) since the last frame.
Source:

(abstract) resize(w, h)

Automatically called when the browser resizes. Can be used in your own Scene classes to resposition stuff. No need to call `super.resize()`.
Parameters:
Name Type Description
w number The new width of the game canvas.
h number The new height of the game canvas.
Source:

restart()

Simply restart this scene.
Source:

setup()

Internal function for starting the scene again. Use `init` to do your own setup.
Source:

shutdown()

Internal function for stopping the scene and removing everything. Can be overridden, but you must call `super.shutdown()` or it can lead to pretty bad erros and memory leaks.
Source:

(abstract) update(time, delta)

Automatically called every frame. Can be used in your own Scene classes to do game logic. No need to call `super.update()`.
Parameters:
Name Type Description
time number The total time (in milliesconds) since the start of the game.
delta number The time elapsed (in milliseconds) since the last frame.
Source:

Events

addedchild

Notifies when a child is added to this scene. Passes the child that was added.
Type:
Source:

removedchild

Notifies when a child is removed from this scene. Passes the child that was removed.
Type:
Source: