Skip to content

Commit 382d8ed

Browse files
committed
Jsdocs: Tilemap Creator & Factor
1 parent f0e59b3 commit 382d8ed

2 files changed

Lines changed: 48 additions & 16 deletions

File tree

v3/src/gameobjects/tilemap/TilemapCreator.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@ var ParseToTilemap = require('./ParseToTilemap');
33

44
// When registering a factory function 'this' refers to the GameObjectCreator context.
55

6+
/**
7+
* Creates a Tilemap from the given key or data, or creates a blank Tilemap if no key/data provided.
8+
*
9+
* @param {object} [config] - The config options for the Tilemap.
10+
* @param {string} [config.key] - The key in the Phaser cache that corresponds to the loaded tilemap
11+
* data.
12+
* @param {array} [config.data] - Instead of loading from the cache, you can also load directly from
13+
* a 2D array of tile indexes.
14+
* @param {number} [config.tileWidth=32] - The width of a tile in pixels.
15+
* @param {number} [config.tileHeight=32] - The height of a tile in pixels.
16+
* @param {number} [config.width=10] - The width of the map in tiles.
17+
* @param {number} [config.height=10] - The height of the map in tiles.
18+
* @param {boolean} [config.insertNull=false] - Controls how empty tiles, tiles with an index of -1,
19+
* in the map data are handled. If `true`, empty locations will get a value of `null`. If `false`,
20+
* empty location will get a Tile object with an index of -1. If you've a large sparsely populated
21+
* map and the tile data doesn't need to change then setting this value to `true` will help with
22+
* memory consumption. However if your map is small or you need to update the tiles dynamically,
23+
* then leave the default value set.
24+
* @returns {Tilemap}
25+
*/
626
GameObjectCreator.register('tilemap', function (config)
727
{
8-
// config {
9-
// key: undefined, (string|number),
10-
// tileWidth: 32,
11-
// tileHeight: 32,
12-
// width: 10,
13-
// height: 10,
14-
// data: null (2D array of tile indexes),
15-
// insertNull: false
16-
// }
17-
28+
// Defaults are applied in ParseToTilemap
1829
var c = config !== undefined ? config : {};
19-
return ParseToTilemap(this.scene, c.key, c.tileWidth, c.tileHeight, c.width, c.height, c.data, c.insertNull);
30+
return ParseToTilemap(this.scene, c.key, c.tileWidth, c.tileHeight, c.width, c.height, c.data,
31+
c.insertNull);
2032
});
Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
22
var ParseToTilemap = require('./ParseToTilemap');
33

4-
54
// When registering a factory function 'this' refers to the GameObjectFactory context.
65
//
76
// There are several properties available to use:
@@ -10,17 +9,38 @@ var ParseToTilemap = require('./ParseToTilemap');
109
// this.displayList - a reference to the Display List the Scene owns
1110
// this.updateList - a reference to the Update List the Scene owns
1211

12+
/**
13+
* Creates a Tilemap from the given key or data, or creates a blank Tilemap if no key/data provided.
14+
*
15+
* @param {string} [key] - The key in the Phaser cache that corresponds to the loaded tilemap data.
16+
* @param {number} [tileWidth=32] - The width of a tile in pixels. Pass in `null` to leave as the
17+
* default.
18+
* @param {number} [tileHeight=32] - The height of a tile in pixels. Pass in `null` to leave as the
19+
* default.
20+
* @param {number} [width=10] - The width of the map in tiles. Pass in `null` to leave as the
21+
* default.
22+
* @param {number} [height=10] - The height of the map in tiles. Pass in `null` to leave as the
23+
* default.
24+
* @param {array} [data] - Instead of loading from the cache, you can also load directly from a 2D
25+
* array of tile indexes. Pass in `null` for no data.
26+
* @param {boolean} [insertNull=false] - Controls how empty tiles, tiles with an index of -1, in the
27+
* map data are handled. If `true`, empty locations will get a value of `null`. If `false`, empty
28+
* location will get a Tile object with an index of -1. If you've a large sparsely populated map and
29+
* the tile data doesn't need to change then setting this value to `true` will help with memory
30+
* consumption. However if your map is small or you need to update the tiles dynamically, then leave
31+
* the default value set.
32+
* @returns {Tilemap}
33+
*/
1334
GameObjectFactory.register('tilemap', function (key, tileWidth, tileHeight, width, height, data, insertNull)
1435
{
15-
// Allow users to specify null as default parameter, but convert it to undefined to match what
16-
// the creator function passed to the parser.
36+
// Allow users to specify null to indicate that they want the default value, since null is
37+
// shorter & more legible than undefined. Convert null to undefined to allow ParseToTilemap
38+
// defaults to take effect.
1739
if (key === null) { key = undefined; }
1840
if (tileWidth === null) { tileWidth = undefined; }
1941
if (tileHeight === null) { tileHeight = undefined; }
2042
if (width === null) { width = undefined; }
2143
if (height === null) { height = undefined; }
22-
if (data === null) { data = undefined; }
23-
if (insertNull === null) { insertNull = undefined; }
2444

2545
return ParseToTilemap(this.scene, key, tileWidth, tileHeight, width, height, data, insertNull);
2646
});

0 commit comments

Comments
 (0)