Skip to content

Commit c36babc

Browse files
committed
Code formatting and docs updates.
1 parent aecbd7c commit c36babc

4 files changed

Lines changed: 114 additions & 45 deletions

File tree

src/pixi/extras/Tilemap.js

Lines changed: 96 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,33 @@
1111
* @class PIXI.Tilemap
1212
* @extends {DisplayObjectContainer}
1313
* @param {PIXI.Texture} texture - The tilemap texture.
14-
* @param {integer} mapwidth - The width of the map.
15-
* @param {integer} mapheight - The height of the map.
16-
* @param {integer} tilewidth 0- The width of a single tile.
17-
* @param {integer} tileheight - The height of a single tile.
18-
* @param {Array} layer - Tilemap layer data from the map, arranged in mapheight lists of mapwidth Phaser.Tile objects (2d array).
14+
* @param {integer} displayWidth - The width of the display area. Used as the clipping limit for the shader.
15+
* @param {integer} displayHeight - The height of the display area. Used as the clipping limit for the shader.
16+
* @param {integer} mapWidth - The width of the map.
17+
* @param {integer} mapHeight - The height of the map.
18+
* @param {integer} tileWidth - The width of a single tile.
19+
* @param {integer} tileHeight - The height of a single tile.
20+
* @param {Array} layer - Tilemap layer data from the map, arranged in mapHeight lists of mapWidth Phaser.Tile objects (2d array).
1921
*/
20-
PIXI.Tilemap = function (texture, displaywidth, displayheight, mapwidth, mapheight, tilewidth, tileheight, layer) {
22+
PIXI.Tilemap = function (texture, displayWidth, displayHeight, mapWidth, mapHeight, tileWidth, tileHeight, layer) {
2123

2224
PIXI.DisplayObjectContainer.call(this);
2325

2426
/**
25-
* the clipping limits for this layer
27+
* The clipping limit of the display area.
28+
*
29+
* @property displayWidth
30+
* @type integer
31+
*/
32+
this.displayWidth = displayWidth;
33+
34+
/**
35+
* The clipping limit of the display area.
36+
*
37+
* @property displayHeight
38+
* @type integer
2639
*/
27-
this.displayWidth = displaywidth;
28-
this.displayHeight = displayheight;
40+
this.displayHeight = displayHeight;
2941

3042
/**
3143
* The texture of the Tilemap
@@ -35,41 +47,93 @@ PIXI.Tilemap = function (texture, displaywidth, displayheight, mapwidth, mapheig
3547
*/
3648
this.texture = texture;
3749

38-
// faster access to the tile dimensions
39-
this.tileWide = tilewidth;
40-
this.tileHigh = tileheight;
41-
this.mapWide = mapwidth;
42-
this.mapHigh = mapheight;
50+
/**
51+
* The width of a single tile in pixels.
52+
*
53+
* @property tileWide
54+
* @type integer
55+
*/
56+
this.tileWide = tileWidth;
4357

44-
// TODO: switch here to create DisplayObjectContainer at correct size for the render mode
58+
/**
59+
* The height of a single tile in pixels.
60+
*
61+
* @property tileHigh
62+
* @type integer
63+
*/
64+
this.tileHigh = tileHeight;
65+
66+
/**
67+
* The width of the map in tiles.
68+
*
69+
* @property mapWide
70+
* @type integer
71+
*/
72+
this.mapWide = mapWidth;
73+
74+
/**
75+
* The height of the map in tiles.
76+
*
77+
* @property mapHigh
78+
* @type integer
79+
*/
80+
this.mapHigh = mapHeight;
81+
82+
/**
83+
* The width of the map in pixels.
84+
*
85+
* @property width
86+
* @type integer
87+
*/
4588
this.width = this.mapWide * this.tileWide;
89+
90+
/**
91+
* The height of the map in pixels.
92+
*
93+
* @property height
94+
* @type integer
95+
*/
4696
this.height = this.mapHigh * this.tileHigh;
4797

98+
/**
99+
* Tilemap layer data from the map, arranged in mapHeight lists of mapWidth tiles.
100+
* Contains Phaser.Tile objects (2d array).
101+
*
102+
* @property layer
103+
* @type Array
104+
*/
48105
this.layer = layer;
49106

50-
// store the list of batch drawing instructions (for use with WebGL rendering)
107+
/**
108+
* Store the list of batch drawing instructions.
109+
*
110+
* @property glBatch
111+
* @type Array
112+
*/
51113
this.glBatch = null;
52114

53115
/**
54-
* Remember last tile drawn to avoid unnecessary set-up
116+
* Remember last tile drawn to avoid unnecessary set-up.
55117
*
56-
* @type Integer
118+
* @property lastTile
119+
* @type integer
57120
*/
58121
this.lastTile = -1;
59122

60123
/**
61-
* Whether the Tilemap is dirty or not
124+
* Whether the Tilemap is dirty or not.
62125
*
63126
* @property dirty
64-
* @type Boolean
127+
* @type boolean
65128
*/
66129
this.dirty = true;
67130

68131
/**
69-
* The blend mode to be applied to the tilemap. Set to PIXI.blendModes.NORMAL to remove any blend mode.
132+
* The blend mode to be applied to the tilemap.
133+
* Set to PIXI.blendModes.NORMAL to remove any blend mode.
70134
*
71135
* @property blendMode
72-
* @type Number
136+
* @type integer
73137
* @default PIXI.blendModes.NORMAL;
74138
*/
75139
this.blendMode = PIXI.blendModes.NORMAL;
@@ -80,19 +144,22 @@ PIXI.Tilemap = function (texture, displaywidth, displayheight, mapwidth, mapheig
80144
* float left, bottom, right, top - screen coordinates
81145
* float u, v, wide, high - source texture coordinates
82146
*
83-
* @type {Number}
147+
* @property batchDataElement
148+
* @type integer
84149
*/
85150
this.batchDataElement = 16;
86151

87-
// calculate total batch data size
88-
var dataSize = mapwidth * mapheight * this.batchDataElement;
89-
90-
// create buffer data for the webgl rendering of this tile
91-
this.buffer = new PIXI.Float32Array(dataSize);
152+
/**
153+
* Create the buffer data for the WebGL rendering of this tilemap.
154+
* Calculates the total batch data size.
155+
*
156+
* @property buffer
157+
* @type PIXI.Float32Array
158+
*/
159+
this.buffer = new PIXI.Float32Array(mapWidth * mapHeight * this.batchDataElement);
92160

93161
};
94162

95-
// constructor, this class extends PIXI.DisplayObjectContainer
96163
PIXI.Tilemap.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
97164
PIXI.Tilemap.prototype.constructor = PIXI.Tilemap;
98165

src/tilemap/Tilemap.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ Phaser.Tilemap = function (game, key, tileWidth, tileHeight, width, height) {
136136
*/
137137
this.images = data.images;
138138

139+
/**
140+
* @property {boolean} enableDebug - If set then console.log is used to dump out useful layer creation debug data.
141+
*/
142+
this.enableDebug = false;
143+
139144
/**
140145
* @property {number} currentLayer - The current layer.
141146
*/
@@ -589,11 +594,11 @@ Phaser.Tilemap.prototype = {
589594
return;
590595
}
591596

592-
if ( this.game.config.enableDebug )
597+
if (this.enableDebug)
593598
{
594-
// incredibly useful when trying to debug multiple layers..
595-
// this and the two below describe each layer, tileset, and it's index in the layers list...
596-
console.log("createLayer", this.layers[index].name, width, "x", height, "tileset", this.tilesets[0].name, "index =", index);
599+
// incredibly useful when trying to debug multiple layers.
600+
// this and the two below describe each layer, tileset, and its index in the layers list.
601+
console.log('Tilemap.createLayer', this.layers[index].name, width, 'x', height, 'tileset', this.tilesets[0].name, 'index:', index);
597602
}
598603

599604
// attempt to create internal layers for multiple tilesets in a layer
@@ -603,20 +608,21 @@ Phaser.Tilemap.prototype = {
603608
{
604609
var ts = this.tilesets[i];
605610
var li = this.layers[index];
606-
if ( !this.createInternalLayer('layer' + index + '_internal_' + i, ts, li, ts.tileWidth, ts.tileHeight, group) )
611+
612+
if (!this.createInternalLayer('layer' + index + '_internal_' + i, ts, li, ts.tileWidth, ts.tileHeight, group))
607613
{
608-
if ( this.game.config.enableDebug )
614+
if (this.enableDebug)
609615
{
610616
// we didn't create an internal layer, this tileset isn't used in the base layer
611-
console.log( "tileset", ts.name, "is not used in layer", li.name );
617+
console.log('Tilemap.createLayer: tileset', ts.name, 'is not used in layer', li.name);
612618
}
613619
}
614620
else
615621
{
616-
if ( this.game.config.enableDebug )
622+
if (this.enableDebug)
617623
{
618624
// we removed all tiles belonging to the tileset in the base layer, and placed them in a new internal layer
619-
console.log( "created internal layer for tileset", ts.name, "from layer", li.name, "index =", this.layers.length - 1 );
625+
console.log('Tilemap.createLayer: Created internal layer for tileset', ts.name, 'from layer', li.name, 'index:', this.layers.length - 1);
620626
}
621627
}
622628
}

src/tilemap/TilemapLayerGL.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,7 @@ Phaser.TilemapLayerGL.prototype.destroy = function() {
279279
};
280280

281281
/**
282-
* Resizes the internal dimensions and texture frame used by this TilemapLayerGL.
283-
*
284-
* This is an expensive call, so don't bind it to a window resize event! But instead call it at carefully
285-
* selected times.
286-
*
287-
* Be aware that no validation of the new sizes takes place and the current map scroll coordinates are not
288-
* modified either. You will have to handle both of these things from your game code if required.
282+
* Resizes the internal dimensions used by this TilemapLayerGL during rendering.
289283
*
290284
* @method Phaser.TilemapLayerGL#resize
291285
* @param {number} width - The new width of the TilemapLayerGL
@@ -296,6 +290,7 @@ Phaser.TilemapLayerGL.prototype.resize = function (width, height) {
296290
this.displayWidth = width;
297291
this.displayHeight = height;
298292
this.dirty = true;
293+
299294
};
300295

301296
/**

typescript/phaser.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5028,6 +5028,7 @@ declare module Phaser {
50285028
collideIndexes: any[];
50295029
currentLayer: number;
50305030
debugMap: any[];
5031+
enableDebug: boolean;
50315032
format: number;
50325033
game: Phaser.Game;
50335034
height: number;

0 commit comments

Comments
 (0)