Tileset
Represents a collection of tiles used by a tilemap.
A tileset contains the image data and metadata for tiles that can be placed in a tilemap. Each tile is identified by a global ID (GID) that's unique across all tilesets in a tilemap. Tilesets support various features including tile spacing, margins, and slope definitions for physics interactions.
Features
- Tile Organization: Tiles arranged in a grid with configurable spacing and margins
- Global IDs: Each tile has a unique GID for referencing across layers
- Slope Support: Define collision slopes for individual tiles
- Grid Orientation: Support for orthogonal and isometric tile arrangements
- Reactive Properties: Extends Model for automatic change notifications
Usage Example
var tileset = new Tileset();
tileset.name = "terrain";
tileset.firstGid = 1;
tileset.tileSize(32, 32);
tileset.image = tilesetImage;
// Add a slope for tile index 5
tileset.slope(5, {
index: 5,
y0: 0.0, // Left edge height (0 = bottom, 1 = top)
y1: 0.5, // Right edge height
rotation: 0 // Optional rotation
});
Instance Members
Reference to the source LDtk tileset definition when this tileset was imported from LDtk. Provides access to additional LDtk-specific metadata.
First global id. Maps to the first tile in this tileset.
The name of this tileset
The (maximum) width of tiles in this tileset
The (maximum) height of tiles in this tileset
The spacing between tiles in this tileset
The margin around the tiles in this tileset
The number of tiles in this tileset
The number of tile columns in this tileset
The number of tile rows in this tileset
The image used to display tiles in this tileset
Orientation of the grid for the tiles in this tileset. Only used in case of isometric orientation, to determine how tile overlays for terrain an collision information are rendered.
Width of a grid cell. Only used in case of isometric orientation, to determine how tile overlays for terrain an collision information are rendered.
Height of a grid cell. Only used in case of isometric orientation, to determine how tile overlays for terrain an collision information are rendered.
The texture used to display tiles in this tileset.
This is a shorthand of image.texture
Slopes in this tileset or null if there is no slope.
A shorthand to set tileWidth
and tileHeight
Name | Type | Description |
---|---|---|
tileWidth |
Int | * |
tileHeight |
Int |
Get the global id from the given column and row coordinates in the tileset.
Name | Type | Description |
---|---|---|
column |
Float | The column position in the tileset (0-based) |
row |
Float | The row position in the tileset (0-based) |
Returns | Description |
---|---|
Int | The global tile ID at the specified position |
Gets the column position of a tile within this tileset from its global ID.
Name | Type | Description |
---|---|---|
gid |
Int | The global tile ID |
Returns | Description |
---|---|
Int | The column position (0-based) within the tileset |
Gets the row position of a tile within this tileset from its global ID.
Name | Type | Description |
---|---|---|
gid |
Int | The global tile ID |
Returns | Description |
---|---|
Int | The row position (0-based) within the tileset |
Add a slope to this tileset.
Name | Type |
---|---|
slope |
TileSlope |
Private Members
A mapping to access a given slope by it's tile index without having to walk through the whole slope array
Internal: true
if TilesetImage instance was created
implicitly from assigning a texture object.
Event when ldtkTileset field changes.
Name | Type |
---|---|
current |
LdtkTilesetDefinition |
previous |
LdtkTilesetDefinition |
Event when firstGid field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when name field changes.
Name | Type |
---|---|
current |
String |
previous |
String |
Event when tileWidth field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when tileHeight field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when spacing field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when margin field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when tileCount field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when columns field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when rows field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when image field changes.
Name | Type |
---|---|
current |
TilesetImage |
previous |
TilesetImage |
Event when gridOrientation field changes.
Name | Type |
---|---|
current |
Anonymous |
previous |
Anonymous |
Event when gridCellWidth field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
Event when gridCellHeight field changes.
Name | Type |
---|---|
current |
Int |
previous |
Int |
emitSlopesChange(current: ReadOnlyArray<TileSlope>, previous: ReadOnlyArray<TileSlope>): Void
Event when slopes field changes.
Name | Type |
---|---|
current |
ReadOnlyArray<TileSlope> |
previous |
ReadOnlyArray<TileSlope> |
Returns |
---|
String |
Metadata
Name | Parameters |
---|---|
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |
:build |
tracker.macros.ObservableMacro.build() |
:autoBuild |
tracker.macros.ObservableMacro.build() |
:build |
tracker.macros.SerializableMacro.build() |
:autoBuild |
tracker.macros.SerializableMacro.build() |