Skip to main content
Version: Phaser v4.0.0-rc.6

TilemapGPULayer

A TilemapGPULayer is a special kind of Game Object that renders LayerData from a Tilemap.

Unlike the more flexible TilemapLayer, this object uses a single Tileset

and is optimized for speed and quality over flexibility.

Use it for high-performance rendering of tilemaps which don't update

their contents. It still supports tile animation and flip.

This layer is designed to be used with the WebGL renderer only.

Performance of this layer is excellent. If you do not need to

manipulate the tiles in the layer, and the layer is of the supported type,

this is the best option for rendering tilemaps.

It is almost entirely GPU-bound, so it will free up CPU resources

for other game code (the CPU usually does much more work than the GPU in games).

It has a fixed cost per pixel on screen, whether there is anything in that

tile or not.

In general, it suffers no performance loss when many tiles are visible.

Create a TilemapGPULayer by adding the gpu flag to a call to

Tilemap.createLayer(). This will return a TilemapGPULayer instance.

This layer has the following abilities and restrictions:

  • Use a single tileset, with a single texture image.

  • Maximum tilemap size of 4096x4096 tiles.

  • Maximum of 2^23 (8388608) unique tile IDs.

  • Tiles may be flipped.

  • Tiles may be animated.

  • Animation data limit of 8388608 entries (each animation or each frame of animation uses one entry).

  • Orthographic tilemaps only.

The layer renders via a special shader.

This uses a texture containing the layer tile data, and a second texture

containing any tile animations. The shader then renders the tiles

as a single quad. Because it doesn't have to compute individual tiles

on the CPU, this is much faster than a TilemapLayer.

However, because it treats tiles as a single orthographic grid,

it is not suitable for use with isometric or hexagonal tilemaps,

or other types of tilemap that require different rendering methods.

If the tileset image uses NEAREST minfiltering, the shader will render

sharp edged pixels. Otherwise, it assumes LINEAR filtering.

The shader will automatically render smooth borders between tiles

in LINEAR mode, with no seams or bleeding, for perfect results.

A regular TilemapLayer cannot render smooth borders like this,

creating sharp seams between tiles.

The layer can be edited, but it will not update automatically.

Regenerate the layer tile data texture by calling generateLayerDataTexture.

Constructor

new TilemapGPULayer(scene, tilemap, layerIndex, tileset, [x], [y])

Parameters

nametypeoptionaldescription
scenePhaser.SceneNoThe Scene to which this TilemapGPULayer belongs.
tilemapPhaser.Tilemaps.TilemapNoThe Tilemap this layer is a part of.
layerIndexnumberNoThe index of the LayerData associated with this layer.
tilesetstring | Phaser.Tilemaps.TilesetNoThe tileset used to render the tiles in this layer. Can be a string or a Tileset object.
xnumberYesThe world x position where the top left of this layer will be placed.
ynumberYesThe world y position where the top left of this layer will be placed.

Scope: static

Extends

Phaser.Tilemaps.TilemapLayerBase

Source: src/tilemaps/TilemapGPULayer.js#L12
Since: 4.0.0

Inherited Members

From Phaser.GameObjects.Components.Alpha:

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.ComputedSize:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.ElapseTimer:

From Phaser.GameObjects.Components.Filters:

From Phaser.GameObjects.Components.Flip:

From Phaser.GameObjects.Components.Lighting:

From Phaser.GameObjects.Components.Mask:

From Phaser.GameObjects.Components.RenderNodes:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.GameObject:

From Phaser.Tilemaps.TilemapLayerBase:


Public Members

layerDataTexture

layerDataTexture: Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper

Description:

A texture containing the tile data for this game object.

Each texel describes a single tile in the layer.

Each texel is stored as a 32-bit value, encoded thus:

  • 1 bit: Horizontal flip flag.

  • 1 bit: Vertical flip flag.

  • 1 bit: Animation flag.

  • 1 bit: Unused.

  • 28 bits: Tile index.

Source: src/tilemaps/TilemapGPULayer.js#L99
Since: 4.0.0


tileset

tileset: Phaser.Tilemaps.Tileset

Description:

The Tileset associated with this layer.

Unlike a TilemapLayer, this object can only have one tileset,

because the renderer is optimized for a single texture.

Source: src/tilemaps/TilemapGPULayer.js#L87
Since: 3.50.0


Inherited Methods

From Phaser.Events.EventEmitter:

From Phaser.GameObjects.Components.Alpha:

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.ComputedSize:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.ElapseTimer:

From Phaser.GameObjects.Components.Filters:

From Phaser.GameObjects.Components.Flip:

From Phaser.GameObjects.Components.GetBounds:

From Phaser.GameObjects.Components.Lighting:

From Phaser.GameObjects.Components.Mask:

From Phaser.GameObjects.Components.Origin:

From Phaser.GameObjects.Components.RenderNodes:

From Phaser.GameObjects.Components.RenderSteps:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.GameObject:

From Phaser.Physics.Arcade.Components.Collision:

From Phaser.Tilemaps.TilemapLayerBase:


Public Methods

generateLayerDataTexture

<instance> generateLayerDataTexture()

Description:

Generate the data textures for this game object.

This method is called internally by setTileset.

Source: src/tilemaps/TilemapGPULayer.js#L161
Since: 4.0.0