mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 13:43:26 +00:00
Copy update: copy all tile props and recalculate faces within dest region
This commit is contained in:
parent
dfa3cc243a
commit
6ca7c9ecfd
4 changed files with 20 additions and 9 deletions
|
@ -41,7 +41,7 @@ var Tile = new Class({
|
||||||
this.tint = 0xFFFFFF;
|
this.tint = 0xFFFFFF;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Copy everything except position
|
// Copy everything except position & interesting faces
|
||||||
copy: function (tile)
|
copy: function (tile)
|
||||||
{
|
{
|
||||||
this.index = tile.index;
|
this.index = tile.index;
|
||||||
|
|
|
@ -189,13 +189,13 @@ var Tilemap = new Class({
|
||||||
return layer;
|
return layer;
|
||||||
},
|
},
|
||||||
|
|
||||||
copy: function (srcTileX, srcTileY, width, height, destTileX, destTileY, layer)
|
copy: function (srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces, layer)
|
||||||
{
|
{
|
||||||
layer = this.getLayer(layer);
|
layer = this.getLayer(layer);
|
||||||
if (this._isStaticCall(layer, 'copy')) { return this; }
|
if (this._isStaticCall(layer, 'copy')) { return this; }
|
||||||
if (layer !== null)
|
if (layer !== null)
|
||||||
{
|
{
|
||||||
TilemapComponents.Copy(srcTileX, srcTileY, width, height, destTileX, destTileY, layer);
|
TilemapComponents.Copy(srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces, layer);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
var GetTilesWithin = require('./GetTilesWithin');
|
var GetTilesWithin = require('./GetTilesWithin');
|
||||||
|
var CalculateFacesWithin = require('./CalculateFacesWithin');
|
||||||
|
|
||||||
// Copies indices, not other properties. Does not modify collisions.
|
// Copies indices, not other properties. Does not modify collisions.
|
||||||
var Copy = function (srcTileX, srcTileY, width, height, destTileX, destTileY, layer)
|
var Copy = function (srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces, layer)
|
||||||
{
|
{
|
||||||
if (srcTileX === undefined || srcTileX < 0) { srcTileX = 0; }
|
if (srcTileX < 0) { srcTileX = 0; }
|
||||||
if (srcTileY === undefined || srcTileY < 0) { srcTileY = 0; }
|
if (srcTileY < 0) { srcTileY = 0; }
|
||||||
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
||||||
|
|
||||||
var srcTiles = GetTilesWithin(srcTileX, srcTileY, width, height, null, layer);
|
var srcTiles = GetTilesWithin(srcTileX, srcTileY, width, height, null, layer);
|
||||||
|
|
||||||
|
@ -17,9 +19,18 @@ var Copy = function (srcTileX, srcTileY, width, height, destTileX, destTileY, la
|
||||||
var tileY = srcTiles[i].y + offsetY;
|
var tileY = srcTiles[i].y + offsetY;
|
||||||
if (tileX >= 0 && tileX < layer.width && tileY >= 0 && tileY < layer.height)
|
if (tileX >= 0 && tileX < layer.width && tileY >= 0 && tileY < layer.height)
|
||||||
{
|
{
|
||||||
layer.data[tileY][tileX].index = srcTiles[i].index;
|
if (layer.data[tileY][tileX])
|
||||||
|
{
|
||||||
|
layer.data[tileY][tileX].copy(srcTiles[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (recalculateFaces)
|
||||||
|
{
|
||||||
|
// Recalculate the faces within the destination area and neighboring tiles
|
||||||
|
CalculateFacesWithin(destTileX - 1, destTileY - 1, width + 2, height + 2, layer);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Copy;
|
module.exports = Copy;
|
||||||
|
|
|
@ -60,9 +60,9 @@ var DynamicTilemapLayer = new Class({
|
||||||
TilemapComponents.CullTiles(this.layer, camera, this.culledTiles);
|
TilemapComponents.CullTiles(this.layer, camera, this.culledTiles);
|
||||||
},
|
},
|
||||||
|
|
||||||
copy: function (srcTileX, srcTileY, width, height, destTileX, destTileY)
|
copy: function (srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces)
|
||||||
{
|
{
|
||||||
TilemapComponents.Copy(srcTileX, srcTileY, width, height, destTileX, destTileY, this.layer);
|
TilemapComponents.Copy(srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces, this.layer);
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue