phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
36.74k stars 7.07k forks source link

Tilemap support for spacing and/or margin broken since 3.80 #6823

Closed damian-pastorini closed 5 days ago

damian-pastorini commented 2 months ago

Version

3.80.1

Description

Since 3.80 if you try to use a Tilemap with spacing and/or margin the Tilemap displayes fully broken (tiles out of place):

image

Example Test Code

My code base is quite big by now, but it's open source, so my implementation can be see between: https://github.com/damian-pastorini/reldens/blob/master/lib/game/client/scene-preloader.js and https://github.com/damian-pastorini/reldens/blob/master/lib/game/client/scene-dynamic.js

To summarize it, I'm using:

scene.load.spritesheet(imageKey, `/maps/${imageFileName}`, tileData);

And then:

scene.map.addTilesetImage(
                imageFileName,
                imageKey,
                tileData.width,
                tileData.height,
                tileData.margin,
                tileData.spacing
            )

These files will show the broken case:

reldens-house-1

These are loaded fine in the TileMapEditor app and work fine in version <=3.70. You can see it in my demo (https://demo.reldens.com):

image

image

If I remove the margin and spacing then it works fine in >=3.80:

reldens-house-1

Additional Information

I've been using the Tile extruder and adding margin and spacing to the maps because prior to 3.80 I've always had the "extrude" issue when the player moves and then you see the lines between the tiles, but if I resize the files to their original 32x32 and remove the spacing and margin the "extrude" issue is not visible anymore, so though the spacing support is broken now I was able to avoid the original issue anyway.

Thanks for all your hard work!!!

damian-pastorini commented 2 months ago

After further test "extrude" the tiles is still required in some cases:

image

I'm trying to fix the tileset in betwee, but getting the spacing / margin support fixed would help.

Thanks again!

damian-pastorini commented 2 months ago

Update: the issue is when you combine: load.spritesheet with tilemaps with spacing / margin, it just doesn't work since 3.80.

scene.load.spritesheet(imageFile, /assets/maps/${imageFile}, tileData); scene.load.image('Desert', 'https://demo.reldens.com/assets/maps/reldens-house-1.png');

Issue visible here: https://phaser.io/sandbox/5orKEN3E switch between 3.80 and 3.70.

photonstorm commented 5 days ago

Strangely, simply swapping the example to load.image worked perfectly (instead of load.spritesheet which is rarely needed for a tileset), which at least allowed me to narrow it down and find a fix in the Texture class.