Constructor
new World(options)
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | An options object to setup some properties of this world. Usually passed in by the game config.
Properties
|
- Source:
Extends
Members
bodies :Array.<module:physics~Body>
Where all the bodies are stored.
Type:
- Array.<module:physics~Body>
- Source:
colliders :Array.<objects>
Where all the colliders are stored.
Type:
- Array.<objects>
- Source:
engine :module:core~Engine
A reference to the main engine.
Type:
- Overrides:
- Source:
gravityX :number
The world's gravity along the x-axis.
Type:
- number
- Default Value:
- 0
- Source:
gravityY :number
The world's gravity along the y-axis.
Type:
- number
- Default Value:
- 0
- 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 ScenePlugin in the game config. If you gave the plugin the name `whiskymixer`, it will become available in the scene as property like in `this.whiskymixer`.
Type:
- string
- Overrides:
- Source:
scene :module:core~Scene
A reference to the scene where this plugin is active.
Type:
- Overrides:
- Source:
worldBoundsRestitution :number
How hard the bodies bounce off the bounds of this world. 0 means they don't bounce. 1 means their velocity gets reversed.
Type:
- number
- Default Value:
- 1
- Source:
Methods
addBody(body)
Adds a body to this world.
Parameters:
Name | Type | Description |
---|---|---|
body |
module:physics~Body | The body to add. |
- Source:
addCollider(config) → {object}
Adds a collider.
Parameters:
Name | Type | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
object | A config object setting the properties for the collider.
Properties
|
- Source:
Returns:
- Type
- object
collideRect(a, b) → {boolean}
Checks wether 2 bodies are overlapping.
Parameters:
Name | Type | Description |
---|---|---|
a |
module:physics~Body | The first body. |
b |
module:physics~Body | The second body. |
- Source:
Returns:
- Type
- boolean
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:
getCollidersOfBody(body) → {Array.<objects>}
Returns all the colliders associated with the body.
Parameters:
Name | Type | Description |
---|---|---|
body |
module:physics~Body | The body to check. |
- Source:
Returns:
- Type
- Array.<objects>
init()
Called by the scene when it starts to do some internal setup for the world.
- Overrides:
- 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:
(abstract) postRender(context, time, delta)
Called on each frame if the scene is active. After all children are rendered.
No need to call `super.postRender(context, time, delta)`
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. |
- Overrides:
- Source:
removeBody(body)
Remove a body from this world and unlinks the colliders.
Parameters:
Name | Type | Description |
---|---|---|
body |
module:physics~Body | The body to remove. |
- Source:
removeCollider(collider)
Removes a collider.
Parameters:
Name | Type | Description |
---|---|---|
collider |
object | The object that was returned by addCollider |
- Source:
seperateAFromB(a, b, delta)
Seprates two bodies that are colliding and displaces the first body.
Parameters:
Name | Type | Description |
---|---|---|
a |
module:physics~Body | The first body. |
b |
module:physics~Body | The second body. |
delta |
number | The time elapsed (in seconds) since the last frame. |
- Source:
seperateBoth(a, b, delta)
Seprates two bodies that are colliding and displaces them both.
Parameters:
Name | Type | Description |
---|---|---|
a |
module:physics~Body | The first body. |
b |
module:physics~Body | The second body. |
delta |
number | The time elapsed (in seconds) since the last frame. |
- Source:
setBounds(x, y, width, height)
Helper to set the bounds of this world.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | The left x position of the area relative to the scene's origin. |
y |
number | The top y position of the area relative to the scene's origin. |
width |
number | The width of the area. |
height |
number | The height of the area. |
- Source:
shutdown()
Automatically called when the scen shuts down. Removes the references to the bodies and the colliders.
- Overrides:
- Source:
update(time, delta)
Called on each frame if the scene is active. Before all children are rendered. Updates all the bodies and processes collisions.
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. |
- Overrides:
- Source: