ObjectHelper
Resolves Tiled object GIDs to their corresponding Tileset data and applies per-tile properties from Tilesets to objects. It assists in creating Game Objects from Tiled object layers by providing texture frames, animations, and custom properties defined in the Tiled editor.
Constructor
new ObjectHelper(tilesets)
Parameters
| name | type | optional | description |
|---|---|---|---|
| tilesets | Array.<Phaser.Tilemaps.Tileset> | No | The backing tileset data. |
Scope: static
Source: src/tilemaps/ObjectHelper.js#L9
Since: 3.60.0
Public Members
enabled
enabled: boolean
Description:
Enabled if the object helper reaches in to tilesets for data. Disabled if it only uses data directly on a gid object.
Source: src/tilemaps/ObjectHelper.js#L63
Since: 3.60.0
gids
gids: array
Description:
A sparse array mapping Tile GID indices to their corresponding Tileset object, populated during construction. Used to look up tileset data by GID at runtime.
Source: src/tilemaps/ObjectHelper.js#L29
Since: 3.60.0
Public Methods
getTypeIncludingTile
<instance> getTypeIncludingTile(obj)
Description:
Gets the Tiled type field value from the object or the gid behind it.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| obj | Phaser.Types.Tilemaps.TiledObject | No | The Tiled object to investigate. |
Returns: string - The type of the object, the tile behind the gid of the object, or undefined.
Source: src/tilemaps/ObjectHelper.js#L85
Since: 3.60.0
setPropertiesFromTiledObject
<instance> setPropertiesFromTiledObject(sprite, obj)
Description:
Sets the sprite.data field from the tiled properties on the object and its tile (if any).
Parameters:
| name | type | optional | description |
|---|---|---|---|
| sprite | Phaser.GameObjects.GameObject | No | The Game Object on which to set the data. |
| obj | Phaser.Types.Tilemaps.TiledObject | No | The Tiled object whose properties will be applied. |
Source: src/tilemaps/ObjectHelper.js#L171
Since: 3.60.0
setTextureAndFrame
<instance> setTextureAndFrame(sprite, [key], [frame], [obj])
Description:
Sets the sprite texture data as specified (usually in a config) or, failing that, as specified in the gid of the object being loaded (if any).
This fallback will only work if the tileset was loaded as a spritesheet matching the geometry of sprites fed into tiled, so that, for example: "tile id #3" within the tileset is the same as texture frame 3 from the image of the tileset.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| sprite | Phaser.GameObjects.GameObject | No | The Game Object to modify. |
| key | string | Phaser.Textures.Texture | Yes | The texture key to set (or else the obj.gid's tile is used if available). |
| frame | string | number | Phaser.Textures.Frame | Yes |
| obj | Phaser.Types.Tilemaps.TiledObject | Yes | The Tiled object for fallback. |
Source: src/tilemaps/ObjectHelper.js#L124
Since: 3.60.0