Tilemap.createDynamicLayer fails to set a default values when called without x and y.
Version
- Phaser Version: 3.16.2
- Operating system: mac os
- Browser: latest chrome (73) and firefox (66)
Description
For some strange reason Tilemap.createDynamicLayer fails to set a default y value when called without x and y.
Test with:
Call map.createDynamicLayer('MyLayer', 'MyTileset') without specifying x and y, the layer is created with an x of 0 (or offsetx) but y is set to undefined.
Expected: The y value should be set to 0 or the offsety that was parsed from tiled, just like the x value.
From src/tilemaps/Tilemap.js:
// Default the x/y position to match Tiled layer offset, if it exists.
if (x === undefined && this.layers[index].x) { x = this.layers[index].x; }
if (y === undefined && this.layers[index].y) { y = this.layers[index].y; }
// ---> Here 'y' is left being undefined !!
var layer = new DynamicTilemapLayer(this.scene, this, index, tileset, x, y);
EDIT: After a some debugging the error was quite obvious. The if fails every time when this.layers[index].x or this.layers[index].y are 0 (they are falsy values!). Also LayerData will always have x and y defined and by default they are 0 so these if will always fail unless offsetx and offsety values in the map file are defined and different from 0.
SOLUTION
Change those lines for these and everything works as intended:
if (x === undefined) { x = layerData.x; }
if (y === undefined) { y = layerData.y; }
var layer = new DynamicTilemapLayer(this.scene, this, index, tileset, x, y);
Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.