Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing tilemap in spriteOverlapsTile callback leads to uncertain result #4819

Open
felixtsu opened this issue Jun 19, 2022 · 1 comment
Open
Labels
bug Something isn't working p2 tilemap Tile map related issues

Comments

@felixtsu
Copy link
Contributor

felixtsu commented Jun 19, 2022

Describe the bug
Changing tilemap in spriteOverlapsTile callback leads to uncertain result

To Reproduce

  1. https://makecode.com/_fKuUxqDkwA3q
  2. Touching tilePath5 from left results in tilemap level 2, touching from right results in tilemap level 3

Expected behavior
should result in tilemap level 2

Screenshots
Screen-Recording-2022-06-19-at-0

Additional context
https://github.com/microsoft/pxt-common-packages/blob/f40bb636d27d44e58ace6e6da06b41af055fc8a7/libs/game/physics.ts#L597

protected tilemapOverlaps(sprite: Sprite, overlappedTiles: tiles.Location[]) {
        const alreadyHandled: tiles.Location[] = [];

        // save current tile map before loop
        let currentTileMap = game.currentScene().tileMap

        for (const tile of overlappedTiles) {
            if (alreadyHandled.some(l => l.column === tile.column && l.row === tile.row)) {
                continue;
            }
            alreadyHandled.push(tile);

            const tileOverlapHandlers = game.currentScene().tileOverlapHandlers;
            if (tileOverlapHandlers) {
            // use saved tile map tiles, preventing tile map changed in handlers
                tileOverlapHandlers
                    .filter(h => h.spriteKind == sprite.kind() && h.tileKind.equals(currentTileMap.getTileImage(tile)))
                    .forEach(h => h.handler(sprite, tile));
            }
        }
    }
felixtsu added a commit to felixtsu/pxt-common-packages that referenced this issue Jun 19, 2022
felixtsu added a commit to felixtsu/pxt-common-packages that referenced this issue Jun 19, 2022
@abchatra abchatra added bug Something isn't working p2 tilemap Tile map related issues labels Sep 28, 2022
@abchatra
Copy link
Contributor

Repros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p2 tilemap Tile map related issues
Projects
None yet
Development

No branches or pull requests

2 participants