Skip to content

TileMap.createFromTiles doesn't properly handle multiple tilesets #7122

Open
@vikerman

Description

@vikerman

Version

  • Phaser Version: 3.88.2

Description

Tilemap.createFromTiles with useSpriteSheet specified in the SpriteConfig assigns the frame number just using the current tile index without taking into account that the tile index doesn't always start from 1 for all tilesets other than the very first one.

Example Test Code

https://stackblitz.com/~/github.com/vikerman/my-phaser-game

The sprites created from the second tileset are all wrong
Image

To test the fix locally comment lines 221-230 and uncomment lines 233-242 in Game.ts in the StackBlitz .

Sprites are properly created after the fix

Image

Additional Information

The line at

config.frame = tile.index - 1;

            config.frame = tile.index - 1;

needs to be changed to

             config.frame = tile.index - tile.tileset.firstgid;

Tested the fix locally by creating a secondary copy of createFromTiles in my project and applying the above fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions