Skip to content

Commit 80185eb

Browse files
committed
Fill update: jsdocs & allow fill to update tile collisions + faces
1 parent 09224b7 commit 80185eb

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

v3/src/gameobjects/tilemap/Tilemap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ var Tilemap = new Class({
209209
this.scene = undefined;
210210
},
211211

212-
fill: function (index, tileX, tileY, width, height, layer)
212+
fill: function (index, tileX, tileY, width, height, recalculateFaces, layer)
213213
{
214214
layer = this.getLayer(layer);
215215
if (this._isStaticCall(layer, 'fill')) { return this; }
216216
if (layer !== null)
217217
{
218-
TilemapComponents.Fill(index, tileX, tileY, width, height, layer);
218+
TilemapComponents.Fill(index, tileX, tileY, width, height, recalculateFaces, layer);
219219
}
220220
return this;
221221
},

v3/src/gameobjects/tilemap/components/Fill.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,46 @@
11
var GetTilesWithin = require('./GetTilesWithin');
2+
var CalculateFacesWithin = require('./CalculateFacesWithin');
3+
4+
/**
5+
* Sets the tiles in the given rectangular area (in tile coordinates) with the specified index.
6+
* Tiles will be set to collide if the given index is a colliding index. Interesting tile faces in
7+
* the region will be recalculated.
8+
*
9+
* @param {number} index - [description]
10+
* @param {number} tileX - [description]
11+
* @param {number} tileY - [description]
12+
* @param {number} width - [description]
13+
* @param {number} height - [description]
14+
* @param {boolean} [recalculateFaces=true] - [description]
15+
* @param {LayerData} layer - [description]
16+
*/
217

318
// Fills indices, not other properties. Does not modify collisions. Matches v2 functionality.
4-
var Fill = function (index, tileX, tileY, width, height, layer)
19+
var Fill = function (index, tileX, tileY, width, height, recalculateFaces, layer)
520
{
21+
if (recalculateFaces === undefined) { recalculateFaces = true; }
22+
23+
var doesIndexCollide = (layer.collideIndexes.indexOf(index) !== -1);
24+
625
var tiles = GetTilesWithin(tileX, tileY, width, height, null, layer);
726
for (var i = 0; i < tiles.length; i++)
827
{
928
tiles[i].index = index;
29+
30+
if (doesIndexCollide)
31+
{
32+
tiles[i].setCollision(true);
33+
}
34+
else
35+
{
36+
tiles[i].resetCollision();
37+
}
38+
}
39+
40+
if (recalculateFaces)
41+
{
42+
// Recalculate the faces within the area and neighboring tiles
43+
CalculateFacesWithin(tileX - 1, tileY - 1, width + 2, height + 2, layer);
1044
}
1145
};
1246

v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ var DynamicTilemapLayer = new Class({
7676
GameObject.prototype.destroy.call(this);
7777
},
7878

79-
fill: function (index, tileX, tileY, width, height)
79+
fill: function (index, tileX, tileY, width, height, recalculateFaces)
8080
{
81-
TilemapComponents.Fill(index, tileX, tileY, width, height, this.layer);
81+
TilemapComponents.Fill(index, tileX, tileY, width, height, recalculateFaces, this.layer);
8282
return this;
8383
},
8484

0 commit comments

Comments
 (0)