Class: CompositeTilemap

CompositeTilemap

A tilemap composite that lazily builds tilesets layered into multiple tilemaps.

The composite tileset is the concatenation of the individual tilesets used in the tilemaps. You can preinitialized it by passing a list of tile textures to the constructor. Otherwise, the composite tilemap is lazily built as you add more tiles with newer tile textures. A new tilemap is created once the last tilemap has reached its limit (as set by texturesPerTilemap).

new CompositeTilemap (tileset)

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

setBitmaps Deprecated : Since @pixi/tilemap 3.

Alias for tileset.

texPerChild number Deprecated : Since @pixi/tilemap 3. readonly

See:

texturesPerTilemap number readonly

The hard limit on the number of tile textures used in each tilemap.

tileAnim [number, number]

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

addFrame (texture, x, y, animX, animY, animWidth, animHeight, animDivisor, alpha) this Deprecated`` : Since @pixi/tilemap 3.

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

addRect (textureIndex, u, v, x, y, tileWidth, tileHeight, animX, animY, rotate, animWidth, animHeight) this Deprecated`` : @pixi/tilemap 3

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

clear () this

Clears the tilemap composite.

Returns:
Type Description
this

tile (tileTexture, x, y, options) 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.

tileAnimDivisor (divisor) this

Changes tileAnimDivisor value of the last added tile.

Name Type Description
divisor number
Returns:
Type Description
this

tileAnimX (offset, count) this

Changes animX, animCountX of the last added tile.

Name Type Description
offset number
count number
Returns:
Type Description
this

tileAnimY (offset, count) this

Changes animY, animCountY of the last added tile.

Name Type Description
offset number
count number
Returns:
Type Description
this

tileRotate (rotate) this

Changes the rotation of the last added tile.

Name Type Description
rotate number
Returns:
Type Description
this

tileset (tileTextures) 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