mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 07:01:20 +00:00
Code formatting and docs updates.
This commit is contained in:
parent
aecbd7c267
commit
c36babcc1c
4 changed files with 114 additions and 45 deletions
|
@ -11,21 +11,33 @@
|
|||
* @class PIXI.Tilemap
|
||||
* @extends {DisplayObjectContainer}
|
||||
* @param {PIXI.Texture} texture - The tilemap texture.
|
||||
* @param {integer} mapwidth - The width of the map.
|
||||
* @param {integer} mapheight - The height of the map.
|
||||
* @param {integer} tilewidth 0- The width of a single tile.
|
||||
* @param {integer} tileheight - The height of a single tile.
|
||||
* @param {Array} layer - Tilemap layer data from the map, arranged in mapheight lists of mapwidth Phaser.Tile objects (2d array).
|
||||
* @param {integer} displayWidth - The width of the display area. Used as the clipping limit for the shader.
|
||||
* @param {integer} displayHeight - The height of the display area. Used as the clipping limit for the shader.
|
||||
* @param {integer} mapWidth - The width of the map.
|
||||
* @param {integer} mapHeight - The height of the map.
|
||||
* @param {integer} tileWidth - The width of a single tile.
|
||||
* @param {integer} tileHeight - The height of a single tile.
|
||||
* @param {Array} layer - Tilemap layer data from the map, arranged in mapHeight lists of mapWidth Phaser.Tile objects (2d array).
|
||||
*/
|
||||
PIXI.Tilemap = function (texture, displaywidth, displayheight, mapwidth, mapheight, tilewidth, tileheight, layer) {
|
||||
PIXI.Tilemap = function (texture, displayWidth, displayHeight, mapWidth, mapHeight, tileWidth, tileHeight, layer) {
|
||||
|
||||
PIXI.DisplayObjectContainer.call(this);
|
||||
|
||||
/**
|
||||
* the clipping limits for this layer
|
||||
* The clipping limit of the display area.
|
||||
*
|
||||
* @property displayWidth
|
||||
* @type integer
|
||||
*/
|
||||
this.displayWidth = displaywidth;
|
||||
this.displayHeight = displayheight;
|
||||
this.displayWidth = displayWidth;
|
||||
|
||||
/**
|
||||
* The clipping limit of the display area.
|
||||
*
|
||||
* @property displayHeight
|
||||
* @type integer
|
||||
*/
|
||||
this.displayHeight = displayHeight;
|
||||
|
||||
/**
|
||||
* The texture of the Tilemap
|
||||
|
@ -35,41 +47,93 @@ PIXI.Tilemap = function (texture, displaywidth, displayheight, mapwidth, mapheig
|
|||
*/
|
||||
this.texture = texture;
|
||||
|
||||
// faster access to the tile dimensions
|
||||
this.tileWide = tilewidth;
|
||||
this.tileHigh = tileheight;
|
||||
this.mapWide = mapwidth;
|
||||
this.mapHigh = mapheight;
|
||||
/**
|
||||
* The width of a single tile in pixels.
|
||||
*
|
||||
* @property tileWide
|
||||
* @type integer
|
||||
*/
|
||||
this.tileWide = tileWidth;
|
||||
|
||||
// TODO: switch here to create DisplayObjectContainer at correct size for the render mode
|
||||
/**
|
||||
* The height of a single tile in pixels.
|
||||
*
|
||||
* @property tileHigh
|
||||
* @type integer
|
||||
*/
|
||||
this.tileHigh = tileHeight;
|
||||
|
||||
/**
|
||||
* The width of the map in tiles.
|
||||
*
|
||||
* @property mapWide
|
||||
* @type integer
|
||||
*/
|
||||
this.mapWide = mapWidth;
|
||||
|
||||
/**
|
||||
* The height of the map in tiles.
|
||||
*
|
||||
* @property mapHigh
|
||||
* @type integer
|
||||
*/
|
||||
this.mapHigh = mapHeight;
|
||||
|
||||
/**
|
||||
* The width of the map in pixels.
|
||||
*
|
||||
* @property width
|
||||
* @type integer
|
||||
*/
|
||||
this.width = this.mapWide * this.tileWide;
|
||||
|
||||
/**
|
||||
* The height of the map in pixels.
|
||||
*
|
||||
* @property height
|
||||
* @type integer
|
||||
*/
|
||||
this.height = this.mapHigh * this.tileHigh;
|
||||
|
||||
/**
|
||||
* Tilemap layer data from the map, arranged in mapHeight lists of mapWidth tiles.
|
||||
* Contains Phaser.Tile objects (2d array).
|
||||
*
|
||||
* @property layer
|
||||
* @type Array
|
||||
*/
|
||||
this.layer = layer;
|
||||
|
||||
// store the list of batch drawing instructions (for use with WebGL rendering)
|
||||
/**
|
||||
* Store the list of batch drawing instructions.
|
||||
*
|
||||
* @property glBatch
|
||||
* @type Array
|
||||
*/
|
||||
this.glBatch = null;
|
||||
|
||||
/**
|
||||
* Remember last tile drawn to avoid unnecessary set-up
|
||||
* Remember last tile drawn to avoid unnecessary set-up.
|
||||
*
|
||||
* @type Integer
|
||||
* @property lastTile
|
||||
* @type integer
|
||||
*/
|
||||
this.lastTile = -1;
|
||||
|
||||
/**
|
||||
* Whether the Tilemap is dirty or not
|
||||
* Whether the Tilemap is dirty or not.
|
||||
*
|
||||
* @property dirty
|
||||
* @type Boolean
|
||||
* @type boolean
|
||||
*/
|
||||
this.dirty = true;
|
||||
|
||||
/**
|
||||
* The blend mode to be applied to the tilemap. Set to PIXI.blendModes.NORMAL to remove any blend mode.
|
||||
* The blend mode to be applied to the tilemap.
|
||||
* Set to PIXI.blendModes.NORMAL to remove any blend mode.
|
||||
*
|
||||
* @property blendMode
|
||||
* @type Number
|
||||
* @type integer
|
||||
* @default PIXI.blendModes.NORMAL;
|
||||
*/
|
||||
this.blendMode = PIXI.blendModes.NORMAL;
|
||||
|
@ -80,19 +144,22 @@ PIXI.Tilemap = function (texture, displaywidth, displayheight, mapwidth, mapheig
|
|||
* float left, bottom, right, top - screen coordinates
|
||||
* float u, v, wide, high - source texture coordinates
|
||||
*
|
||||
* @type {Number}
|
||||
* @property batchDataElement
|
||||
* @type integer
|
||||
*/
|
||||
this.batchDataElement = 16;
|
||||
|
||||
// calculate total batch data size
|
||||
var dataSize = mapwidth * mapheight * this.batchDataElement;
|
||||
|
||||
// create buffer data for the webgl rendering of this tile
|
||||
this.buffer = new PIXI.Float32Array(dataSize);
|
||||
/**
|
||||
* Create the buffer data for the WebGL rendering of this tilemap.
|
||||
* Calculates the total batch data size.
|
||||
*
|
||||
* @property buffer
|
||||
* @type PIXI.Float32Array
|
||||
*/
|
||||
this.buffer = new PIXI.Float32Array(mapWidth * mapHeight * this.batchDataElement);
|
||||
|
||||
};
|
||||
|
||||
// constructor, this class extends PIXI.DisplayObjectContainer
|
||||
PIXI.Tilemap.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
|
||||
PIXI.Tilemap.prototype.constructor = PIXI.Tilemap;
|
||||
|
||||
|
|
|
@ -136,6 +136,11 @@ Phaser.Tilemap = function (game, key, tileWidth, tileHeight, width, height) {
|
|||
*/
|
||||
this.images = data.images;
|
||||
|
||||
/**
|
||||
* @property {boolean} enableDebug - If set then console.log is used to dump out useful layer creation debug data.
|
||||
*/
|
||||
this.enableDebug = false;
|
||||
|
||||
/**
|
||||
* @property {number} currentLayer - The current layer.
|
||||
*/
|
||||
|
@ -589,11 +594,11 @@ Phaser.Tilemap.prototype = {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( this.game.config.enableDebug )
|
||||
if (this.enableDebug)
|
||||
{
|
||||
// incredibly useful when trying to debug multiple layers..
|
||||
// this and the two below describe each layer, tileset, and it's index in the layers list...
|
||||
console.log("createLayer", this.layers[index].name, width, "x", height, "tileset", this.tilesets[0].name, "index =", index);
|
||||
// incredibly useful when trying to debug multiple layers.
|
||||
// this and the two below describe each layer, tileset, and its index in the layers list.
|
||||
console.log('Tilemap.createLayer', this.layers[index].name, width, 'x', height, 'tileset', this.tilesets[0].name, 'index:', index);
|
||||
}
|
||||
|
||||
// attempt to create internal layers for multiple tilesets in a layer
|
||||
|
@ -603,20 +608,21 @@ Phaser.Tilemap.prototype = {
|
|||
{
|
||||
var ts = this.tilesets[i];
|
||||
var li = this.layers[index];
|
||||
if ( !this.createInternalLayer('layer' + index + '_internal_' + i, ts, li, ts.tileWidth, ts.tileHeight, group) )
|
||||
|
||||
if (!this.createInternalLayer('layer' + index + '_internal_' + i, ts, li, ts.tileWidth, ts.tileHeight, group))
|
||||
{
|
||||
if ( this.game.config.enableDebug )
|
||||
if (this.enableDebug)
|
||||
{
|
||||
// we didn't create an internal layer, this tileset isn't used in the base layer
|
||||
console.log( "tileset", ts.name, "is not used in layer", li.name );
|
||||
console.log('Tilemap.createLayer: tileset', ts.name, 'is not used in layer', li.name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( this.game.config.enableDebug )
|
||||
if (this.enableDebug)
|
||||
{
|
||||
// we removed all tiles belonging to the tileset in the base layer, and placed them in a new internal layer
|
||||
console.log( "created internal layer for tileset", ts.name, "from layer", li.name, "index =", this.layers.length - 1 );
|
||||
console.log('Tilemap.createLayer: Created internal layer for tileset', ts.name, 'from layer', li.name, 'index:', this.layers.length - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -279,13 +279,7 @@ Phaser.TilemapLayerGL.prototype.destroy = function() {
|
|||
};
|
||||
|
||||
/**
|
||||
* Resizes the internal dimensions and texture frame used by this TilemapLayerGL.
|
||||
*
|
||||
* This is an expensive call, so don't bind it to a window resize event! But instead call it at carefully
|
||||
* selected times.
|
||||
*
|
||||
* Be aware that no validation of the new sizes takes place and the current map scroll coordinates are not
|
||||
* modified either. You will have to handle both of these things from your game code if required.
|
||||
* Resizes the internal dimensions used by this TilemapLayerGL during rendering.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#resize
|
||||
* @param {number} width - The new width of the TilemapLayerGL
|
||||
|
@ -296,6 +290,7 @@ Phaser.TilemapLayerGL.prototype.resize = function (width, height) {
|
|||
this.displayWidth = width;
|
||||
this.displayHeight = height;
|
||||
this.dirty = true;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
1
typescript/phaser.d.ts
vendored
1
typescript/phaser.d.ts
vendored
|
@ -5028,6 +5028,7 @@ declare module Phaser {
|
|||
collideIndexes: any[];
|
||||
currentLayer: number;
|
||||
debugMap: any[];
|
||||
enableDebug: boolean;
|
||||
format: number;
|
||||
game: Phaser.Game;
|
||||
height: number;
|
||||
|
|
Loading…
Reference in a new issue