Skip to content

Commit

Permalink
Layers now remove themselves from the Tilemap when destroyed. Fix #4319
Browse files Browse the repository at this point in the history
  • Loading branch information
photonstorm committed Apr 8, 2019
1 parent a8027ba commit d63321e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -64,6 +64,8 @@ Notes:
* `Matter.World.resetCollisionIDs` is a new method that will reset the collision IDs that Matter JS uses for body collision groups. You should call this before destroying your game if you need to restart the game again on the same page, without first reloading the page. Or, if you wish to consistently destroy a Scene that contains Matter.js and then run it again (thanks @clesquir)
* RenderTexture has two new optional constructor arguments `key` and `frame`. This allows you to create a RenderTexture pre-populated with the size and frame from an existing texture (thanks @TadejZupancic)
* `GameObjects.Components.PathFollower` is a new component that manages any type of Game Object following a path. The original Path Follower Game Object has been updated to use this new component directly, but it can be applied to any custom Game Object class.
* `Tilemap.removeLayer` is a new method that allows you to remove a specific layer from a Tilemap without destroying it.
* `Tilemap.destroyLayer` is a new method that allows you to destroy a layer and remove it from a Tilemap.

### Updates

Expand All @@ -83,6 +85,8 @@ Notes:
* `Graphics.lineFxTo` and `Graphics.moveFxTo` have been removed as they were not being rendered anyway.
* You can now use "infinite" tilemaps as created in Tiled v1.1 and above. Support is basic in that it takes the chunk data and builds one giant map from it. However, at least you are still able to now load and use infinite maps, even if they don't chunk during the game (thanks @Upperfoot)
* `MapData.infinite` is a new boolean that controls if the map data is infinite or not.
* `DynamicTilemapLayer.destroy` will now remove the layer from the Tilemap it belongs to, clearing it from the layers array. Fix #4319 (thanks @APXEOLOG)
* `StaticTilemapLayer.destroy` will now remove the layer from the Tilemap it belongs to, clearing it from the layers array. Fix #4319 (thanks @APXEOLOG)

### Bug Fixes

Expand All @@ -106,6 +110,7 @@ Notes:
* `Texture.add` will no longer let you add a frame to a texture with the same name or index as one that already exists in the texture. Doing so will now return `null` instead of a Frame object, and the `frameTotal` will never be incremented. Fix #4459 (thanks @BigZaphod)
* The InputPlugin will now dispatch an update event regardless, allowing the Gamepad Plugin to update itself every frame, regardless of DOM events. This allows Gamepads to work correctly again. Fix #4414 (thanks @CipSoft-Components)


### Examples, Documentation and TypeScript

My thanks to the following for helping with the Phaser 3 Examples, Docs and TypeScript definitions, either by reporting errors, fixing them or helping author the docs:
Expand Down
4 changes: 3 additions & 1 deletion src/tilemaps/dynamiclayer/DynamicTilemapLayer.js
Expand Up @@ -454,12 +454,14 @@ var DynamicTilemapLayer = new Class({
*/
destroy: function ()
{
// Uninstall this layer only if it is still installed on the LayerData object
// Uninstall this layer only if it is still installed on the LayerData object
if (this.layer.tilemapLayer === this)
{
this.layer.tilemapLayer = undefined;
}

this.tilemap.removeLayer(this);

this.tilemap = undefined;
this.layer = undefined;
this.culledTiles.length = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/tilemaps/staticlayer/StaticTilemapLayer.js
Expand Up @@ -1448,6 +1448,8 @@ var StaticTilemapLayer = new Class({
this.layer.tilemapLayer = undefined;
}

this.tilemap.removeLayer(this);

this.tilemap = undefined;
this.layer = undefined;
this.culledTiles.length = 0;
Expand Down

0 comments on commit d63321e

Please sign in to comment.