Name | Type | Attributes | Description |
---|---|---|---|
tileset |
Array<TextureSource> |
<optional> |
A list of tile base-textures that will be used to eagerly initialized the layered tilemaps. This is only an performance optimization, and using tile will work equivalently. |
Example
import { Application } from '@pixi/app';
import { CompositeTilemap } from '@pixi/tilemap';
import { Loader } from '@pixi/loaders';
// Setup view & stage.
const app = new Application();
document.body.appendChild(app.renderer.view);
app.stage.interactive = true;
// Global reference to the tilemap.
let globalTilemap: CompositeTilemap;
// Load the tileset spritesheet!
Loader.shared.load('atlas.json');
// Initialize the tilemap scene when the assets load.
Loader.shared.load(function onTilesetLoaded()
{
const tilemap = new CompositeTilemap();
// Setup the game level with grass and dungeons!
for (let x = 0; x < 10; x++)
{
for (let y = 0; y < 10; y++)
{
tilemap.tile(
x % 2 === 0 && (x === y || x + y === 10) ? 'dungeon.png' : 'grass.png',
x * 100,
y * 100,
);
}
}
globalTilemap = app.stage.addChild(tilemap);
});
// Show a bomb at a random location whenever the user clicks!
app.stage.on('click', function onClick()
{
if (!globalTilemap) return;
const x = Math.floor(Math.random() * 10);
const y = Math.floor(Math.random() * 10);
globalTilemap.tile('bomb.png', x * 100, y * 100);
});
Extends
- Container
Members
Alias for tileset.
- See:
The hard limit on the number of tile textures used in each tilemap.
The animation frame vector.
Animated tiles have four parameters - animX
, animY
, animCountX
, animCountY
. The textures
of adjacent animation frames are at offset animX
or animY
of each other, with animCountX
per
row and animCountY
per column.
The animation frame vector specifies which animation frame texture to use. If the x/y coordinate is
larger than the animCountX
or animCountY
for a specific tile, the modulus is taken.
- Default Value:
- undefined
lastModifiedTilemap Tilemap protected
The last modified tilemap.
- Default Value:
- undefined
Methods
Name | Type | Attributes | Description |
---|---|---|---|
texture |
Texture | string | number | ||
x |
number | ||
y |
number | ||
animX |
number |
<optional> |
|
animY |
number |
<optional> |
|
animWidth |
number |
<optional> |
|
animHeight |
number |
<optional> |
|
animDivisor |
number |
<optional> |
|
alpha |
number |
<optional> |
- See:
Returns:
Type | Description |
---|---|
this |
Name | Type | Attributes | Description |
---|---|---|---|
textureIndex |
number | ||
u |
number | ||
v |
number | ||
x |
number | ||
y |
number | ||
tileWidth |
number | ||
tileHeight |
number | ||
animX |
number |
<optional> |
|
animY |
number |
<optional> |
|
rotate |
number |
<optional> |
|
animWidth |
number |
<optional> |
|
animHeight |
number |
<optional> |
- See:
Returns:
Type | Description |
---|---|
this |
Clears the tilemap composite.
Returns:
Type | Description |
---|---|
this |
Adds a tile that paints the given tile texture at (x, y).
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
tileTexture |
Texture | string | number |
The tile texture. You can pass an index into the composite tilemap as well. |
||
x |
number |
The local x-coordinate of the tile's location. |
||
y |
number |
The local y-coordinate of the tile's location. |
||
options |
{ u?: number, v?: number, tileWidth?: number, tileHeight?: number, animX?: number, animY?: number, rotate?: number, animCountX?: number, animCountY?: number, animDivisor?: number, alpha?: number } |
Additional options to pass to tile. |
||
options.u |
<optional> |
texture.frame.x |
The x-coordinate of the texture in its base-texture's space. |
|
options.v |
<optional> |
texture.frame.y |
The y-coordinate of the texture in its base-texture's space. |
|
options.tileWidth |
<optional> |
texture.orig.width |
The local width of the tile. |
|
options.tileHeight |
<optional> |
texture.orig.height |
The local height of the tile. |
|
options.animX |
<optional> |
0 |
For animated tiles, this is the "offset" along the x-axis for adjacent animation frame textures in the base-texture. |
|
options.animY |
<optional> |
0 |
For animated tiles, this is the "offset" along the y-axis for adjacent animation frames textures in the base-texture. |
|
options.rotate |
<optional> |
0 | ||
options.animCountX |
<optional> |
1024 |
For animated tiles, this is the number of animation frame textures per row. |
|
options.animCountY |
<optional> |
1024 |
For animated tiles, this is the number of animation frame textures per column. |
|
options.animDivisor |
<optional> |
1 |
For animated tiles, this is the animation duration each frame |
|
options.alpha |
<optional> |
1 |
Tile alpha |
Returns:
Type | Description |
---|---|
this | This tilemap, good for chaining. |
Changes tileAnimDivisor
value of the last added tile.
Name | Type | Description |
---|---|---|
divisor |
number |
Returns:
Type | Description |
---|---|
this |
Changes animX
, animCountX
of the last added tile.
Name | Type | Description |
---|---|---|
offset |
number | |
count |
number |
Returns:
Type | Description |
---|---|
this |
Changes animY
, animCountY
of the last added tile.
Name | Type | Description |
---|---|---|
offset |
number | |
count |
number |
Returns:
Type | Description |
---|---|
this |
Changes the rotation of the last added tile.
Name | Type | Description |
---|---|---|
rotate |
number |
Returns:
Type | Description |
---|---|
this |
This will preinitialize the tilesets of the layered tilemaps.
If used after a tilemap has been created (or a tile added), this will overwrite the tile textures of the existing tilemaps. Passing the tileset to the constructor instead is the best practice.
Name | Type | Description |
---|---|---|
tileTextures |
Array<TextureSource> |
The list of tile textures that make up the tileset. |
Returns:
Type | Description |
---|---|
this |