The active state of this Game Object.
A Game Object with an active state of true
is processed by the Scenes UpdateList, if added to it.
An active object is one which is having its logic and internal systems updated.
If this Game Object is enabled for Arcade or Matter Physics then this property will contain a reference to a Physics Body.
A bitmask that controls if this Game Object is drawn by a Camera or not.
Not usually set directly, instead call Camera.ignore
, however you can
set this property directly using the Camera.id property:
A Data Manager.
It allows you to store, query and get key/value paired information specific to this Game Object.
null
by default. Automatically created if you use getData
or setData
or setDataEnabled
.
This Game Object will ignore all calls made to its destroy method if this flag is set to true
.
This includes calls that may come from a Group, Container or the Scene itself.
While it allows you to persist a Game Object across Scenes, please understand you are entirely
responsible for managing references to and from this Game Object.
If this Game Object is enabled for input then this property will contain an InteractiveObject instance.
Not usually set directly. Instead call GameObject.setInteractive()
.
The name of this Game Object. Empty by default and never populated by Phaser, this is left for developers to use.
The parent Container of this Game Object, if it has one.
The flags that are compared against RENDER_MASK
to determine if this Game Object will render or not.
The bits are 0001 | 0010 | 0100 | 1000 set by the components Visible, Alpha, Transform and Texture respectively.
If those components are not used by your custom class then you can use this bitmask as you wish.
The Scene to which this Game Object belongs. Game Objects can only belong to one Scene.
The current state of this Game Object.
Phaser itself will never modify this value, although plugins may do so.
Use this property to track the state of a Game Object during its lifetime. For example, it could change from a state of 'moving', to 'attacking', to 'dead'. The state value should be an integer (ideally mapped to a constant in your game code), or a string. These are recommended to keep it light and simple, with fast comparisons. If you need to store complex data about your Game Object, look at using the Data Component instead.
The Tab Index of the Game Object. Reserved for future use by plugins and the Input Manager.
A textual representation of this Game Object, i.e. sprite
.
Used internally by Phaser but is available for your own custom classes to populate.
The bitmask that GameObject.renderFlags
is compared against to determine if the Game Object will render or not.
Add a listener for a given event.
The event name.
The listener function.
The context to invoke the listener with. Default this.
Function iterates over all tiles in terrain layer and character layer, and change their animation state if they are animated.
Destroys this Game Object removing it from the Display List and Update List and severing all ties to parent resources.
Also removes itself from the Input Manager and Physics Manager if previously enabled.
Use this to remove a Game Object from your game if you don't ever plan to use it again. As long as no reference to it exists within your own code it should become free for garbage collection by the browser.
If you just want to temporarily disable an object then look at using the Game Object Pool instead of destroying it, as destroyed objects cannot be resurrected.
Is this Game Object being destroyed as the result of a Scene shutdown? Default false.
If this Game Object has previously been enabled for input, this will disable it.
An object that is disabled for input stops processing or being considered for
input events, but can be turned back on again at any time by simply calling
setInteractive()
with no arguments provided.
If want to completely remove interaction from this Game Object then use removeInteractive
instead.
Calls each of the listeners registered for a given event.
The event name.
Additional arguments that will be passed to the event handler.
Return an array listing the events for which the emitter has registered listeners.
Retrieves the value for the given key in this Game Objects Data Manager, or undefined if it doesn't exist.
You can also access values via the values
object. For example, if you had a key called gold
you can do either:
sprite.getData('gold');
Or access the value directly:
sprite.data.values.gold;
You can also pass in an array of keys, in which case an array of values will be returned:
sprite.getData([ 'gold', 'armor', 'health' ]);
This approach is useful for destructuring arrays in ES6.
The key of the value to retrieve, or an array of keys.
Returns an array containing the display list index of either this Game Object, or if it has one, its parent Container. It then iterates up through all of the parent containers until it hits the root of the display list (which is index 0 in the returned array).
Used internally by the InputPlugin but also useful if you wish to find out the display depth of this Game Object and all of its ancestors.
Function returns world coordinates of the selected tile
Coordinates of currently selected tile or undefined, when there is no selected tile
Function returning data about the tile on the given coordinates in tile space.
X coordinate in tile space
Y coordinate in tile space
Tile info or undefined when there is no tile on the given coordinates
Function transforming the current cursor position to the map coordinates in tile space.
Coordinates of tile under the cursor, in tile space
Increase a value for the given key within this Game Objects Data Manager. If the key doesn't already exist in the Data Manager then it is increased from 0.
If the Game Object has not been enabled for data (via setDataEnabled
) then it will be enabled
before setting the value.
If the key doesn't already exist in the Data Manager then it is created.
When the value is first set, a setdata
event is emitted from this Game Object.
The key to increase the value for.
The value to increase for the given key.
Function which decides whether the tile on the given tile coordinates is part of the currently rendered map region or not.
X coordinate in tile space
Y coordinate in tile space
True if and only if the tile is currently rendered.
Return the number of listeners listening to a given event.
The event name.
Return the listeners registered for a given event.
The event name.
Moves tile selection by deltaX tiles to the right and deltaY to the bottom.
Number of tiles for moving the selection horizontally
Number of tiles for moving the selection vertically
Remove the listeners of a given event.
The event name.
Only remove the listeners that match this function.
Only remove the listeners that have this context.
Only remove one-time listeners.
Add a listener for a given event.
The event name.
The listener function.
The context to invoke the listener with. Default this.
This function is called when the logged account is changed, and redraws players on the map
New logged account
This function is called when there is newly mined block, and redraws spawned items on the map when it is necessary
New mined block
Function which is called whenever some player mined some resource. Then, the corresponding tile is changed from that resource to empty tile.
Info about what player mined resource at what location
Whether this info was added into database, changed in it or removed from it.
Function which is called whenever there is a click event on the game canvas (except when there is a React popup over it), and selects the tile under the cursor as active.
Pointer event
Function which is called whenever the mouse moves over the game canvas, and emits corresponding event containing info about the tile under the cursor.
Pointer event
Whenever the game turn seed changes, this function is called and redraws map terrain and spawned items.
This function zooms or unzooms whole map on wheel event
Wheel event
Add a one-time listener for a given event.
The event name.
The listener function.
The context to invoke the listener with. Default this.
Function changes the terrain on given coordinates to the given type.
New terrain type
X coordinate in tile space
Y coordinate in tile space
This function redraws all layers of map.
Redraws item layer asynchronously.
This function redraws the items layer by clearing it and then rendering spawned items on all coordinates where there currently should be spawned item. This method is very computation-heavy, so it waits (in a non-blocking way) every 128 tiles for 100 ms, so the rest of the app can respond.
Redraws character layer asynchronously.
This function redraws the character layer by clearing it and then rendering all the registered players on their locations.
Redraws terrain layer asynchronously.
This function first redraws the terrain layer based on the current game turn seed, then replace all the minable tiles with empty tiles when they have already been mined.
Remove all listeners, or those of the specified event.
The event name.
If this Game Object has previously been enabled for input, this will queue it for removal, causing it to no longer be interactive. The removal happens on the next game step, it is not immediate.
The Interactive Object that was assigned to this Game Object will be destroyed, removed from the Input Manager and cleared from this Game Object.
If you wish to re-enable this Game Object at a later date you will need to
re-create its InteractiveObject by calling setInteractive
again.
If you wish to only temporarily stop an object from receiving input then use
disableInteractive
instead, as that toggles the interactive state, where-as
this erases it completely.
If you wish to resize a hit area, don't remove and then set it as being
interactive. Instead, access the hitarea object directly and resize the shape
being used. I.e.: sprite.input.hitArea.setSize(width, height)
(assuming the
shape is a Rectangle, which it is by default.)
Remove the listeners of a given event.
The event name.
Only remove the listeners that match this function.
Only remove the listeners that have this context.
Only remove one-time listeners.
Sets the active
property of this Game Object and returns this Game Object for further chaining.
A Game Object with its active
property set to true
will be updated by the Scenes UpdateList.
True if this Game Object should be set as active, false if not.
Allows you to store a key value pair within this Game Objects Data Manager.
If the Game Object has not been enabled for data (via setDataEnabled
) then it will be enabled
before setting the value.
If the key doesn't already exist in the Data Manager then it is created.
sprite.setData('name', 'Red Gem Stone');
You can also pass in an object of key value pairs as the first argument:
sprite.setData({ name: 'Red Gem Stone', level: 2, owner: 'Link', gold: 50 });
To get a value back again you can call getData
:
sprite.getData('gold');
Or you can access the value directly via the values
property, where it works like any other variable:
sprite.data.values.gold += 50;
When the value is first set, a setdata
event is emitted from this Game Object.
If the key already exists, a changedata
event is emitted instead, along an event named after the key.
For example, if you updated an existing key called PlayerLives
then it would emit the event changedata-PlayerLives
.
These events will be emitted regardless if you use this method to set the value, or the direct values
setter.
Please note that the data keys are case-sensitive and must be valid JavaScript Object property strings.
This means the keys gold
and Gold
are treated as two unique values within the Data Manager.
The key to set the value for. Or an object of key value pairs. If an object the data
argument is ignored.
The value to set for the given key. If an object is provided as the key this argument is ignored.
Adds a Data Manager component to this Game Object.
Pass this Game Object to the Input Manager to enable it for Input.
Input works by using hit areas, these are nearly always geometric shapes, such as rectangles or circles, that act as the hit area for the Game Object. However, you can provide your own hit area shape and callback, should you wish to handle some more advanced input detection.
If no arguments are provided it will try and create a rectangle hit area based on the texture frame the Game Object is using. If this isn't a texture-bound object, such as a Graphics or BitmapText object, this will fail, and you'll need to provide a specific shape for it to use.
You can also provide an Input Configuration Object as the only argument to this method.
Either an input configuration object, or a geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used.
A callback to be invoked when the Game Object is interacted with. If you provide a shape you must also provide a callback.
Should this Game Object be treated as a drop zone target? Default false.
Sets the name
property of this Game Object and returns this Game Object for further chaining.
The name
property is not populated by Phaser and is presented for your own use.
The name to be given to this Game Object.
Most low-level method for selecting a tile. It should be called whenever the selection has changed. It receives the coordinates of the newly selected tile in tile space, then shifts the whole map when it is necessary to display the selected tile in center, unset the selection effect from the old tile and set it to the new tile. In the end, it emits the events related with selection
X coordinate of the newly selected tile, in tile space
Y coordinate of the newly selected tile, in tile space
Changes tile selection to the given world coordinates.
X coordinate of the newly selected tile
Y coordinate of the newly selected tile
Sets the current state of this Game Object.
Phaser itself will never modify the State of a Game Object, although plugins may do so.
For example, a Game Object could change from a state of 'moving', to 'attacking', to 'dead'. The state value should typically be an integer (ideally mapped to a constant in your game code), but could also be a string. It is recommended to keep it light and simple. If you need to store complex data about your Game Object, look at using the Data Component instead.
The state of the Game Object.
Removes all listeners.
Function for converting tile space coordinates to world space coordinates
X coordinate in tile space
Y coordinate in tile space
Equivalent coordinates in world space
Returns a JSON representation of the Game Object.
Toggle a boolean value for the given key within this Game Objects Data Manager. If the key doesn't already exist in the Data Manager then it is toggled from false.
If the Game Object has not been enabled for data (via setDataEnabled
) then it will be enabled
before setting the value.
If the key doesn't already exist in the Data Manager then it is created.
When the value is first set, a setdata
event is emitted from this Game Object.
The key to toggle the value for.
To be overridden by custom GameObjects. Allows base objects to be used in a Pool.
args
Compares the renderMask with the renderFlags to see if this Game Object will render or not. Also checks the Game Object against the given Cameras exclusion list.
The Camera to check against this Game Object.
Function for converting world space coordinates to tile space coordinates
X coordinate in world space
Y coordinate in world space
Equivalent coordinates in tile space
Generated using TypeDoc
Phaser GameObject representing game map. It is the only visual element which is ever handler by Phaser in this project. The map can interact with the rest of the project by the injected Context object.