Constructor
new Camera()
- Source:
Fires:
Extends
Members
bounds :object
The area that constrains the movement of the camera. If the bounds is undefined it can move anywhere.
Type:
- object
Properties:
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. |
- Default Value:
- undefined
- Source:
engine :module:core~Engine
A reference to the main engine.
Type:
- Overrides:
- Source:
followTarget :module:gameobjects~GameObject
The game object the camera has to follow. Set to undefined to stop following it.
Type:
- Default Value:
- undefined
- Source:
lerpX :number
A number between 0 and 1 that indicates how much the speed must be smoothed when following a game object. 1 is no smoothing. 0 doesn't change the camera's x position when the game object moves.
Type:
- number
- Default Value:
- 1
- Source:
lerpY :number
Same as lerpX, but along the y axis.
Type:
- number
- Default Value:
- 1
- 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:
x :number
The mid x position of the camera. At the start of the scene this is set to the center of the scene's viewport. You can also set it yourself in the scene's init and update methods.
Type:
- number
- Source:
y :number
The mid y position of the camera. At the start of the scene this is set to the center of the scene's viewport. You can also set it yourself in the scene's init and update methods.
Type:
- number
- Source:
Methods
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:
fade(optionsopt)
Fills the whole viewport with a color. From transparency to opaque.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Optional tweaks to the fade effect.
Properties
|
- Source:
flash(optionsopt)
Fills the whole viewport with a color. From opaque to transparency.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Optional tweaks to the fade effect.
Properties
|
- Source:
init()
Automatically called when the scene starts and sets the x and y to the center of the scene's viewport.
- 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:
postRender(context, time, delta)
Automatically called when the scene has rendered it's children. Used for rendering the fade effects.
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:
setBounds(x, y, width, height)
Helper to set the bounds of this camera.
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:
shake(optionsopt)
Shakes the camera. Use in your game logic whenever there is an impact or some other dramatic thing.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Optional tweaks to the shake effect.
Properties
|
- Source:
(abstract) shutdown()
Called when the scene is shutdown.
Needs to call `super.shutdown()` as well.
- Overrides:
- Source:
update(time, delta)
Automatically called every frame. Updates the camera position if there is a followTarget set. Constrains the movement if a bounds is set. Also applies the shaking effect if there is one going on. Then it updates the scene's offset property.
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:
Events
fadecomplete
Notifies when the camera is done with the fade.
- Source:
flashcomplete
Notifies when the camera is done with the flash.
- Source: