Constructor
new FlatImage(config)
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
object | A config object that sets some basic properties.
Properties
|
- Source:
Extends
Members
body :module:physics~Body
A physics body. Use addBody to attach a body to this game object.
Type:
- Overrides:
- Default Value:
- undefined
- Source:
fillStyle :string
A color to use as fill, when the game object requires a fill.
Type:
- string
- Overrides:
- Default Value:
- #000000
- Source:
height :number
The game object's height.
Type:
- number
- Overrides:
- Source:
lifespan :number
How long this game object will remain on the scene in millieseconds. Use this for things like particles to let the engine remove them automatically. When it is undefined the game object will remain on the scene until it is removed manually or until the scene shuts down.
Type:
- number
- Overrides:
- Default Value:
- undefined
- Source:
listeners :object
A dictionary of the event callbacks attached to this object.
Type:
- object
- Overrides:
- Source:
offsetX :number
How much to displace this game object's x position in relation to the body's x position.
Type:
- number
- Overrides:
- Default Value:
- 0
- Source:
offsetY :number
How much to displace this game object's y position in relation to the body's y position.
Type:
- number
- Overrides:
- Default Value:
- 0
- Source:
scene :module:core~Scene
A reference to the scene this game object is attached to.
Type:
- Overrides:
- Source:
scrollFactorX :number
A number between 0 and 1. How much the game object is influenced by camera movement along the x axis. 1 means the game object keeps it's position in the scene. 0 means it is static in the viewport.
Type:
- number
- Overrides:
- Default Value:
- 1
- Source:
scrollFactorY :number
A number between 0 and 1. How much the game object is influenced by camera movement along the y axis. 1 means the game object keeps it's position in the scene. 0 means it is static in the viewport.
Type:
- number
- Overrides:
- Default Value:
- 1
- Source:
visible :boolean
Wether or not this game object will be rendered.
Type:
- boolean
- Overrides:
- Default Value:
- true
- Source:
width :number
The game object's width.
Type:
- number
- Overrides:
- Source:
x :number
The game object's mid x position.
Type:
- number
- Overrides:
- Source:
y :number
The game object's mid y position.
Type:
- number
- Overrides:
- Source:
Methods
addBody(body) → {module:gameobjects~GameObject}
Adds a physics body to this game object and sets the position, width and height of the physics body to this game object's position, width and height. And returns this game object.
Parameters:
Name | Type | Description |
---|---|---|
body |
module:physics~Body | An instance of a physics body |
- Overrides:
- Source:
Returns:
destroy()
Automatically called when the scene shuts down to clean up events and references. When you override this method, use `super.destroy()`
- Overrides:
- Source:
draw(context)
Draws the image to the screen.
Parameters:
Name | Type | Description |
---|---|---|
context |
CanvasRenderingContext2D | The translated canvas context. |
- Overrides:
- Source:
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:
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:
render(context, offset)
Called automatically every frame. Translates the canvas 2d context to the position of this game object and calls this game object's draw method. And then restores the context.
Parameters:
Name | Type | Description |
---|---|---|
context |
CanvasRenderingContext2D | The canvas render context. |
offset |
object | The scene's offset as manipulated by the camera. |
- Overrides:
- Source: