Skip to content

Fix wrong animated tiles used in TilemapGPULayer#7337

Open
moufmouf wants to merge 1 commit into
phaserjs:masterfrom
moufmouf:fix/tilemapgpulayer-animation-header-index
Open

Fix wrong animated tiles used in TilemapGPULayer#7337
moufmouf wants to merge 1 commit into
phaserjs:masterfrom
moufmouf:fix/tilemapgpulayer-animation-header-index

Conversation

@moufmouf

Copy link
Copy Markdown
Contributor

This PR (delete as applicable)

  • Fixes a bug

Fixes #7331.

createAnimationDataTexture stored the raw animation ordinal in _animationDataIndexMap, but each animation header occupies 2 texels in the animation data texture (duration and frame offset) and the shader reads the header at texel index. Only ordinal 0 landed on a valid header; every animated tile after the first read a bogus header and resolved to a wrong tile.

Store the texel offset (ordinal * 2), matching how the frame offset is already stored. The map value is consumed only by
TilemapGPULayer.generateLayerDataTexture (which looks it up directly) and by SubmitterTilemapGPULayer (which only reads .size), so doubling is safe.

You can view a repro in this fork of the example directory: https://github.com/moufmouf/examples/blob/d2a8077ceb86c3159e67599d89f30e5e9a0a310f/public/src/tilemaps/tilemap%20gpu%20layer/gpu%20tile%20layer%20two%20animated%20tiles.js

(Phaser Sandbox seems down as I am opening this PR)

Before the fix:

bugB-anim-before-annotated

After the fix:

bugB-anim-after-annotated

createAnimationDataTexture stored the raw animation ordinal in
_animationDataIndexMap, but each animation header occupies 2 texels in the
animation data texture (duration and frame offset) and the shader reads the
header at texel `index`. Only ordinal 0 landed on a valid header; every
animated tile after the first read a bogus header and resolved to a wrong tile.

Store the texel offset (`ordinal * 2`), matching how the frame offset is
already stored. The map value is consumed only by
TilemapGPULayer.generateLayerDataTexture (which looks it up directly) and by
SubmitterTilemapGPULayer (which only reads `.size`), so doubling is safe.

Fixes phaserjs#7331.

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.

TilemapGPULayer Animated tiles breaks if 2 or more animated tiles are present in tileset

1 participant