Skip to content

Fix TilemapGPULayer rendering at double its position#7335

Open
moufmouf wants to merge 1 commit into
phaserjs:masterfrom
moufmouf:fix/tilemapgpulayer-double-position
Open

Fix TilemapGPULayer rendering at double its position#7335
moufmouf wants to merge 1 commit into
phaserjs:masterfrom
moufmouf:fix/tilemapgpulayer-double-position

Conversation

@moufmouf

Copy link
Copy Markdown
Contributor

This PR (delete as applicable)

  • Fixes a bug

A TilemapGPULayer placed at (x, y) was rendered at (2x, 2y). The layer's position is already baked into the transform via applyITRS(x, y, ...), but setQuad() was then called with the absolute x/y again, applying the offset twice.

The existing GPU tilemap examples only place layers at (0, 0), so the doubling (2*0 = 0) was never visible and the bug went unnoticed.

A full repro is available in this fork of the examples repository: moufmouf/examples@4e831f6

class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.image('tiles', 'assets/tilemaps/MedievalRTS/medieval_tilesheet.png');
        this.load.tilemapTiledJSON('map', 'assets/tilemaps/MedievalRTS/sample.json');
    }

    create ()
    {
        const OX = 250;
        const OY = 180;

        const map = this.make.tilemap({ key: 'map' });
        const tileset = map.addTilesetImage('medieval_tilesheet', 'tiles', 64, 64);

        // GPU tilemap layer (5th argument = true), positioned at (OX, OY).
        map.createLayer('Land', tileset, OX, OY, true);

        // Marker for the expected top-left corner of the layer.
        this.add.rectangle(OX, OY, 64, 64).setStrokeStyle(2, 0xff00ff).setOrigin(0, 0);
        this.add.text(OX, OY - 22, `createLayer('Land', ts, ${OX}, ${OY}, true)`, {
            fontFamily: 'monospace', fontSize: 15, color: '#ff00ff'
        });
    }
}

Result before the fix:

bugA-position-before-annotated

Result after the fix:

bugA-position-after-annotated

A TilemapGPULayer placed at (x, y) was rendered at (2x, 2y). The layer's
position is already baked into the transform via applyITRS(x, y, ...), but
setQuad() was then called with the absolute x/y again, applying the offset
twice. Build the quad from local (0, 0)-(width, height) coordinates instead.

The existing GPU tilemap examples only place layers at (0, 0), so the
doubling (2*0 = 0) was never visible.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant