mirror of
https://github.com/photonstorm/phaser
synced 2024-11-26 06:30:38 +00:00
Merge pull request #6436 from samme/fix/put-empty-tile
Fix putTileAt() with empty tile
This commit is contained in:
commit
e21bf2dafc
2 changed files with 27 additions and 8 deletions
|
@ -4,6 +4,7 @@
|
||||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var BuildTilesetIndex = require('./parsers/tiled/BuildTilesetIndex');
|
||||||
var Class = require('../utils/Class');
|
var Class = require('../utils/Class');
|
||||||
var DegToRad = require('../math/DegToRad');
|
var DegToRad = require('../math/DegToRad');
|
||||||
var Formats = require('./Formats');
|
var Formats = require('./Formats');
|
||||||
|
@ -244,6 +245,16 @@ var Tilemap = new Class({
|
||||||
*/
|
*/
|
||||||
this.layers = mapData.layers;
|
this.layers = mapData.layers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Master list of tiles -> x, y, index in tileset.
|
||||||
|
*
|
||||||
|
* @name Phaser.Tilemaps.Tilemap#tiles
|
||||||
|
* @type {array}
|
||||||
|
* @since 3.60.0
|
||||||
|
* @see Phaser.Tilemaps.Parsers.Tiled.BuildTilesetIndex
|
||||||
|
*/
|
||||||
|
this.tiles = mapData.tiles;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of Tilesets used in the map.
|
* An array of Tilesets used in the map.
|
||||||
*
|
*
|
||||||
|
@ -420,6 +431,8 @@ var Tilemap = new Class({
|
||||||
|
|
||||||
this.tilesets.push(tileset);
|
this.tilesets.push(tileset);
|
||||||
|
|
||||||
|
this.tiles = BuildTilesetIndex(this);
|
||||||
|
|
||||||
return tileset;
|
return tileset;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -2653,6 +2666,7 @@ var Tilemap = new Class({
|
||||||
{
|
{
|
||||||
this.removeAllLayers();
|
this.removeAllLayers();
|
||||||
|
|
||||||
|
this.tiles.length = 0;
|
||||||
this.tilesets.length = 0;
|
this.tilesets.length = 0;
|
||||||
this.objects.length = 0;
|
this.objects.length = 0;
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ var Tile = require('../Tile');
|
||||||
var IsInLayerBounds = require('./IsInLayerBounds');
|
var IsInLayerBounds = require('./IsInLayerBounds');
|
||||||
var CalculateFacesAt = require('./CalculateFacesAt');
|
var CalculateFacesAt = require('./CalculateFacesAt');
|
||||||
var SetTileCollision = require('./SetTileCollision');
|
var SetTileCollision = require('./SetTileCollision');
|
||||||
var BuildTilesetIndex = require('../parsers/tiled/BuildTilesetIndex');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puts a tile at the given tile coordinates in the specified layer. You can pass in either an index
|
* Puts a tile at the given tile coordinates in the specified layer. You can pass in either an index
|
||||||
|
@ -67,16 +66,22 @@ var PutTileAt = function (tile, tileX, tileY, recalculateFaces, layer)
|
||||||
var newTile = layer.data[tileY][tileX];
|
var newTile = layer.data[tileY][tileX];
|
||||||
var collides = layer.collideIndexes.indexOf(newTile.index) !== -1;
|
var collides = layer.collideIndexes.indexOf(newTile.index) !== -1;
|
||||||
|
|
||||||
// Copy properties from tileset to tiles.
|
|
||||||
var tiles = BuildTilesetIndex(layer.tilemapLayer.tilemap);
|
|
||||||
|
|
||||||
index = tile instanceof Tile ? tile.index : tile;
|
index = tile instanceof Tile ? tile.index : tile;
|
||||||
|
|
||||||
var sid = tiles[index][2];
|
if (index === -1)
|
||||||
var set = layer.tilemapLayer.tileset[sid];
|
{
|
||||||
|
newTile.width = layer.tileWidth;
|
||||||
|
newTile.height = layer.tileHeight;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var tiles = layer.tilemapLayer.tilemap.tiles;
|
||||||
|
var sid = tiles[index][2];
|
||||||
|
var set = layer.tilemapLayer.tileset[sid];
|
||||||
|
|
||||||
newTile.width = set.tileWidth;
|
newTile.width = set.tileWidth;
|
||||||
newTile.height = set.tileHeight;
|
newTile.height = set.tileHeight;
|
||||||
|
}
|
||||||
|
|
||||||
SetTileCollision(newTile, collides);
|
SetTileCollision(newTile, collides);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue