Closed HawkenKing closed 4 months ago
To resolve the issue where a Tilemap object doesn't move when its parent container moves, you need to ensure that the TilemapLayer correctly updates its position based on the container's position. This can be done by overriding the Container.addHandler
method to account for TilemapLayers. Here are the steps:
Container.js
file.addHandler
method to include a check for TilemapLayers and update their positions accordingly.Container.addHandler = function (child) {
if (child.type === 'TilemapLayer') {
child.setPosition(this.x + child.x, this.y + child.y);
}
child.addedToScene();
};
This ensures that when a TilemapLayer is added to a container, its position is updated relative to the container's position.
/changelog/3.80/CHANGELOG-v3.80.md /changelog/3.60/Tilemap.md /changelog/3.14/CHANGELOG-v3.14.md /changelog/3.60/Container.md
Tilemaps should not be added to Containers. They are stand-alone rendering objects. We will add this to the documentation, but you shouldn't use them in this way.
Version
Description
Expectation of tilemap and other objects to move when added to a container and moving the container. Result: other objects move with container, tilemap is stays where it was generated.
Example Test Code
` this.gameContainer = this.add.container(0, 0);
Additional Information
In this screen shot, a sprite is also added at 0,0 then the container is moved to 20,20. The sprite moves with the container but the tilemap stays at its initial added position of 0,0.