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
| name | type | optional | description |
|---|---|---|---|
| scene | Phaser.Scene | No | The Scene to which this TilemapGPULayer belongs. |
| tilemap | Phaser.Tilemaps.Tilemap | No | The Tilemap this layer is a part of. |
| layerIndex | number | No | The index of the LayerData associated with this layer. |
| tileset | string | Phaser.Tilemaps.Tileset | No | The tileset used to render the tiles in this layer. Can be a string or a Tileset object. |
| x | number | Yes | The world x position where the top left of this layer will be placed. |
| y | number | Yes | The world y position where the top left of this layer will be placed. |
Scope: static
Extends
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:
- filterCamera
- filters
- filtersAutoFocus
- filtersFocusContext
- filtersForceComposite
- maxFilterSize
- renderFilters
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:
- active
- body
- cameraFilter
- data
- displayList
- ignoreDestroy
- input
- name
- parentContainer
- renderFlags
- scene
- state
- tabIndex
- type
- vertexRoundMode
From Phaser.Tilemaps.TilemapLayerBase:
- collisionCategory
- collisionMask
- displayOriginX
- displayOriginY
- gidMap
- isTilemap
- layer
- layerIndex
- originX
- originY
- tilemap
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:
- addListener
- emit
- eventNames
- listenerCount
- listeners
- off
- on
- once
- removeAllListeners
- removeListener
- shutdown
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:
- enableFilters
- focusFilters
- focusFiltersOnCamera
- focusFiltersOverride
- renderWebGLFilters
- setFiltersAutoFocus
- setFiltersFocusContext
- setFiltersForceComposite
- setFilterSize
- setRenderFilters
- willRenderFilters
From Phaser.GameObjects.Components.Flip:
From Phaser.GameObjects.Components.GetBounds:
- getBottomCenter
- getBottomLeft
- getBottomRight
- getBounds
- getCenter
- getLeftCenter
- getRightCenter
- getTopCenter
- getTopLeft
- getTopRight
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:
- copyPosition
- getLocalPoint
- getLocalTransformMatrix
- getParentRotation
- getWorldPoint
- getWorldTransformMatrix
- setAngle
- setPosition
- setRandomPosition
- setRotation
- setScale
- setW
- setX
- setY
- setZ
From Phaser.GameObjects.Components.Visible:
From Phaser.GameObjects.GameObject:
- addedToScene
- addToDisplayList
- addToUpdateList
- disableInteractive
- getData
- getDisplayList
- getIndexList
- incData
- removedFromScene
- removeFromDisplayList
- removeFromUpdateList
- removeInteractive
- setActive
- setData
- setDataEnabled
- setInteractive
- setName
- setState
- setVertexRoundMode
- toggleData
- toJSON
- update
- willRender
- willRoundVertices
From Phaser.Physics.Arcade.Components.Collision:
- addCollidesWith
- removeCollidesWith
- resetCollisionCategory
- setCollidesWith
- setCollisionCategory
- willCollideWith
From Phaser.Tilemaps.TilemapLayerBase:
- calculateFacesAt
- calculateFacesWithin
- copy
- createFromTiles
- destroy
- fill
- filterTiles
- findByIndex
- findTile
- forEachTile
- getIsoTileAtWorldXY
- getTileAt
- getTileAtWorldXY
- getTileCorners
- getTilesWithin
- getTilesWithinShape
- getTilesWithinWorldXY
- hasTileAt
- hasTileAtWorldXY
- putTileAt
- putTileAtWorldXY
- putTilesAt
- randomize
- removeTileAt
- removeTileAtWorldXY
- renderDebug
- replaceByIndex
- setCollision
- setCollisionBetween
- setCollisionByExclusion
- setCollisionByProperty
- setCollisionFromCollisionGroup
- setTileIndexCallback
- setTileLocationCallback
- shuffle
- swapByIndex
- tileToWorldX
- tileToWorldXY
- tileToWorldY
- weightedRandomize
- worldToTileX
- worldToTileXY
- worldToTileY
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