From 64547fe042eb2c415648c2b2af58d4a57f2c32c5 Mon Sep 17 00:00:00 2001 From: Sylvain Pollet-Villard Date: Sun, 31 May 2026 20:23:04 +0200 Subject: [PATCH] add Tileset#animating --- src/tilemaps/TilemapLayerWebGLRenderer.js | 2 +- src/tilemaps/Tileset.js | 11 +++++++++++ tests/tilemaps/Tileset.test.js | 1 + types/phaser.d.ts | 20 +++++++++++++++----- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/tilemaps/TilemapLayerWebGLRenderer.js b/src/tilemaps/TilemapLayerWebGLRenderer.js index fb1b4e796a..da82ae7cdc 100644 --- a/src/tilemaps/TilemapLayerWebGLRenderer.js +++ b/src/tilemaps/TilemapLayerWebGLRenderer.js @@ -78,7 +78,7 @@ var TilemapLayerWebGLRenderer = function (renderer, src, drawingContext, parentM continue; } - var tileIndex = tileset.getAnimatedTileId(tile.index, timeElapsed); + var tileIndex = tileset.getAnimatedTileId(tile.index, tileset.animating ? timeElapsed : 0); if (tileIndex === null) { diff --git a/src/tilemaps/Tileset.js b/src/tilemaps/Tileset.js index bc75214198..79315ff480 100644 --- a/src/tilemaps/Tileset.js +++ b/src/tilemaps/Tileset.js @@ -197,6 +197,17 @@ var Tileset = new Class({ */ this.texCoordinates = []; + + /** + * Whether the tileset animations should play or not. If false, animated tiles will stay on their first frame. + * + * @name Phaser.Tilemaps.Tileset#animating + * @type {boolean} + * @since 4.2.0 + * @default true + */ + this.animating = true; + /** * The number of frames above which a tile is considered to have * many animation frames. This is used to optimize rendering. diff --git a/tests/tilemaps/Tileset.test.js b/tests/tilemaps/Tileset.test.js index 7421c09ad3..f2fa96fecc 100644 --- a/tests/tilemaps/Tileset.test.js +++ b/tests/tilemaps/Tileset.test.js @@ -22,6 +22,7 @@ describe('Tileset', function () expect(ts.columns).toBe(0); expect(ts.total).toBe(0); expect(ts.texCoordinates).toEqual([]); + expect(ts.animating).toBe(true); expect(ts.animationSearchThreshold).toBe(64); expect(ts.maxAnimationLength).toBe(0); }); diff --git a/types/phaser.d.ts b/types/phaser.d.ts index 62345ca813..c306ae33b4 100644 --- a/types/phaser.d.ts +++ b/types/phaser.d.ts @@ -130528,7 +130528,8 @@ declare namespace Phaser { * @param y The y coordinate of the pixel within the Texture. * @param key The unique string-based key of the Texture. * @param frame The string or index of the Frame. - * @returns A Color object populated with the color values of the requested pixel, or `null` if the coordinates were out of bounds. + * @returns A Color object populated with the color values of the requested pixel, +or `null` if the coordinates were out of bounds. */ getPixel(x: number, y: number, key: string, frame?: string | number): Phaser.Display.Color | null; @@ -131924,7 +131925,8 @@ declare namespace Phaser { * GID this set will use here. Default 0. * @param tileOffset Tile texture drawing offset. * If not specified, it will default to {0, 0} Default {x: 0, y: 0}. - * @returns Returns the Tileset object that was created or updated, or null if it failed. + * @returns Returns the Tileset object that was created or updated, or null if it +failed. */ addTilesetImage(tilesetName: string, key?: string, tileWidth?: number, tileHeight?: number, tileMargin?: number, tileSpacing?: number, gid?: number, tileOffset?: object): Phaser.Tilemaps.Tileset | null; @@ -137770,6 +137772,11 @@ declare namespace Phaser { */ readonly texCoordinates: object[]; + /** + * Whether the tileset animations should play or not. If false, animated tiles will stay on their first frame. + */ + animating: boolean; + /** * The number of frames above which a tile is considered to have * many animation frames. This is used to optimize rendering. @@ -137833,7 +137840,8 @@ declare namespace Phaser { * Returns the texture coordinates (UV in pixels) in the Tileset image for the given tile index. * Returns null if tile index is not contained in this Tileset. * @param tileIndex The unique id of the tile across all tilesets in the map. - * @returns Object in the form { x, y } representing the top-left UV coordinate within the Tileset image. + * @returns Object in the form { x, y } representing the top-left UV coordinate +within the Tileset image. */ getTileTextureCoordinates(tileIndex: number): object | null; @@ -139243,7 +139251,8 @@ declare namespace Phaser { * @param insertNull Controls how empty tiles (those with an index of -1) are stored in * the LayerData. If `true`, empty tile positions are stored as `null`. If `false`, a Tile object * with an index of -1 is created for each empty position instead. - * @returns - An array of LayerData objects, one for each entry in json.layer. + * @returns - An array of LayerData objects, one for each entry in +json.layer. */ function ParseTileLayers(json: object, insertNull: boolean): Phaser.Tilemaps.LayerData[]; @@ -139412,7 +139421,8 @@ declare namespace Phaser { * @param json The Tiled JSON object. * @param insertNull Controls how empty tiles, tiles with an index of -1, in the map * data are handled (see {@link Phaser.Tilemaps.Parsers.Tiled.ParseJSONTiled}). - * @returns - An array of LayerData objects, one for each entry in json.layers with the type 'tilelayer'. + * @returns - An array of LayerData objects, one for each entry in +json.layers with the type 'tilelayer'. */ function ParseTileLayers(json: object, insertNull: boolean): Phaser.Tilemaps.LayerData[];