Skip to content

Commit 10d7be0

Browse files
committed
Merge branch 'master' of https://github.com/photonstorm/phaser
2 parents 3ee14a8 + 80185eb commit 10d7be0

7 files changed

Lines changed: 77 additions & 8 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/CalculateFacesWithin.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
var GetTileAt = require('./GetTileAt');
22
var GetTilesWithin = require('./GetTilesWithin');
33

4+
/**
5+
* Calculates interesting faces within the rectangular area specified (in tile coordinates).
6+
* Interesting faces are used internally for optimizing collisions against tiles. This method is
7+
* mostly used internally.
8+
*
9+
* @param {number} [tileX=0] - [description]
10+
* @param {number} [tileY=0] - [description]
11+
* @param {number} [width=max width based on tileX] - [description]
12+
* @param {number} [height=max height based on tileY] - [description]
13+
* @param {LayerData} layer - [description]
14+
*/
415
var CalculateFacesWithin = function (tileX, tileY, width, height, layer)
516
{
617
var above = null;

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
var GetTilesWithin = require('./GetTilesWithin');
22
var CalculateFacesWithin = require('./CalculateFacesWithin');
33

4-
// Copies indices, not other properties. Does not modify collisions.
4+
/**
5+
* Copies the tiles in the source rectangular area to a new destination (all specified in tile
6+
* coordinates). This copies all tile properties & recalculates interesting tile faces in the
7+
* destination region.
8+
*
9+
* @param {number} srcTileX - [description]
10+
* @param {number} srcTileY - [description]
11+
* @param {number} width - [description]
12+
* @param {number} height - [description]
13+
* @param {number} destTileX - [description]
14+
* @param {number} destTileY - [description]
15+
* @param {number} destTileY - [description]
16+
* @param {boolean} [recalculateFaces=true] - [description]
17+
* @param {LayerData} layer - [description]
18+
*/
19+
520
var Copy = function (srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces, layer)
621
{
722
if (srcTileX < 0) { srcTileX = 0; }

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
* Returns the tiles in the given layer that are within the camera's viewport. This is used
3+
* internally.
4+
*
5+
* @param {LayerData} layer - [description]
6+
* @param {Camera} camera - [description]
7+
* @param {array} [outputArray] - [description]
8+
* @returns {array}
9+
*/
110
var CullTiles = function (layer, camera, outputArray)
211
{
312
if (outputArray === undefined) { outputArray = []; }

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/components/GetTilesWithinShape.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ var TriangleToRectangle = function (triangle, rect)
1414
};
1515

1616
// Circle, Line, Rect, Triangle in world coordinates.
17-
// Notes: circle is not working yet - see CircleToRectangle in geom. Could possibly be optimized
18-
// by copying the shape and shifting it into tilemapLayer coordinates instead of shifting the tiles.
17+
// Note: Could possibly be optimized by copying the shape and shifting it into tilemapLayer
18+
// coordinates instead of shifting the tiles.
1919
var GetTilesWithinShape = function (shape, filteringOptions, camera, layer)
2020
{
2121
if (shape === undefined) { return []; }

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)