11var GameObjectFactory = require ( '../../scene/plugins/GameObjectFactory' ) ;
22var 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+ */
1334GameObjectFactory . 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