Skip to content

Commit cc7b632

Browse files
committed
Phaser.TilemapParser.INSERT_NULL is a new boolean that controls what happens when the parser encounters an empty tile: When scanning the Tiled map data the TilemapParser can either insert a null value (true) or a Phaser.Tile instance with an index of -1 (false, the default). Depending on your game type depends how this should be configured. If you've a large sparsely populated map and the tile data doesn't need to change then setting this value to true will help with memory consumption. However if your map is small, or you need to update the tiles (perhaps the map dynamically changes during the game) then leave the default value set (thanks phaserjs#1982)
1 parent 0cce3f8 commit cc7b632

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
275275
* BitmapData.line draws a line to the BitmapData in the color and thickness specified.
276276
* BitmapData.op is a handy short-code to get and set the canvas global composite operator.
277277
* BitmapData.drawFull draws the given Game Object or Group to a BitmapData and then recursively iterates through all of its children, including children of Game Objects and Groups. It can draw Text, BitmapText, Sprites, Images, Emitters and Graphics objects. It's perfectly valid to pass in `game.world` as the parent object, and it will iterate through the entire display list.
278+
* Phaser.TilemapParser.INSERT_NULL is a new boolean that controls what happens when the parser encounters an empty tile: When scanning the Tiled map data the TilemapParser can either insert a null value (true) or a `Phaser.Tile` instance with an index of -1 (false, the default). Depending on your game type depends how this should be configured. If you've a large sparsely populated map and the tile data doesn't need to change then setting this value to `true` will help with memory consumption. However if your map is small, or you need to update the tiles (perhaps the map dynamically changes during the game) then leave the default value set (thanks #1982)
278279

279280
### Updates
280281

src/tilemap/TilemapParser.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,22 @@
88
* Phaser.TilemapParser parses data objects from Phaser.Loader that need more preparation before they can be inserted into a Tilemap.
99
*
1010
* @class Phaser.TilemapParser
11+
* @static
1112
*/
1213
Phaser.TilemapParser = {
1314

15+
/**
16+
* When scanning the Tiled map data the TilemapParser can either insert a null value (true) or
17+
* a Phaser.Tile instance with an index of -1 (false, the default). Depending on your game type
18+
* depends how this should be configured. If you've a large sparsely populated map and the tile
19+
* data doesn't need to change then setting this value to `true` will help with memory consumption.
20+
* However if your map is small, or you need to update the tiles (perhaps the map dynamically changes
21+
* during the game) then leave the default value set.
22+
*
23+
* @type {boolean}
24+
*/
25+
INSERT_NULL: false,
26+
1427
/**
1528
* Parse tilemap data from the cache and creates a Tilemap object.
1629
*
@@ -324,9 +337,14 @@ Phaser.TilemapParser = {
324337
}
325338
else
326339
{
327-
// Null option
328-
// row.push(new Phaser.Tile(layer, -1, x, output.length, json.tilewidth, json.tileheight));
329-
row.push(null);
340+
if (Phaser.TilemapParser.INSERT_NULL)
341+
{
342+
row.push(null);
343+
}
344+
else
345+
{
346+
row.push(new Phaser.Tile(layer, -1, x, output.length, json.tilewidth, json.tileheight));
347+
}
330348
}
331349

332350
x++;

0 commit comments

Comments
 (0)