mirror of
https://github.com/wassname/phaser.git
synced 2026-07-11 00:40:20 +08:00
Adding docs.
This commit is contained in:
+61
-31
@@ -1,91 +1,120 @@
|
||||
/**
|
||||
* Phaser - Tile
|
||||
*
|
||||
* A Tile is a single representation of a tile within a Tilemap
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.Tile
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Tile constructor
|
||||
* Create a new <code>Tile</code>.
|
||||
*
|
||||
* @param tilemap {Tilemap} the tilemap this tile belongs to.
|
||||
* @param index {number} The index of this tile type in the core map data.
|
||||
* @param width {number} Width of the tile.
|
||||
* @param height number} Height of the tile.
|
||||
* @class Phaser.Tile
|
||||
* @classdesc A Tile is a single representation of a tile within a Tilemap.
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {Tilemap} tilemap - The tilemap this tile belongs to.
|
||||
* @param {number} index - The index of this tile type in the core map data.
|
||||
* @param {number} width - Width of the tile.
|
||||
* @param {number} height - Height of the tile.
|
||||
*/
|
||||
Phaser.Tile = function (game, tilemap, index, width, height) {
|
||||
|
||||
/**
|
||||
* The virtual mass of the tile.
|
||||
* @type {number}
|
||||
* @property {number} mass - The virtual mass of the tile.
|
||||
* @default
|
||||
*/
|
||||
this.mass = 1.0;
|
||||
|
||||
/**
|
||||
* Indicating this Tile doesn't collide at all.
|
||||
* @type {bool}
|
||||
* @property {bool} collideNone - Indicating this Tile doesn't collide at all.
|
||||
* @default
|
||||
*/
|
||||
this.collideNone = true;
|
||||
|
||||
/**
|
||||
* Indicating collide with any object on the left.
|
||||
* @type {bool}
|
||||
* @property {bool} collideLeft - Indicating collide with any object on the left.
|
||||
* @default
|
||||
*/
|
||||
this.collideLeft = false;
|
||||
|
||||
/**
|
||||
* Indicating collide with any object on the right.
|
||||
* @type {bool}
|
||||
* @property {bool} collideRight - Indicating collide with any object on the right.
|
||||
* @default
|
||||
*/
|
||||
this.collideRight = false;
|
||||
|
||||
/**
|
||||
* Indicating collide with any object on the top.
|
||||
* @type {bool}
|
||||
* @property {bool} collideUp - Indicating collide with any object on the top.
|
||||
* @default
|
||||
*/
|
||||
this.collideUp = false;
|
||||
|
||||
/**
|
||||
* Indicating collide with any object on the bottom.
|
||||
* @type {bool}
|
||||
* @property {bool} collideDown - Indicating collide with any object on the bottom.
|
||||
* @default
|
||||
*/
|
||||
this.collideDown = false;
|
||||
|
||||
/**
|
||||
* Enable separation at x-axis.
|
||||
* @type {bool}
|
||||
* @property {bool} separateX - Enable separation at x-axis.
|
||||
* @default
|
||||
*/
|
||||
this.separateX = true;
|
||||
|
||||
/**
|
||||
* Enable separation at y-axis.
|
||||
* @type {bool}
|
||||
* @property {bool} separateY - Enable separation at y-axis.
|
||||
* @default
|
||||
*/
|
||||
this.separateY = true;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {bool} tilemap - The tilemap this tile belongs to.
|
||||
*/
|
||||
this.tilemap = tilemap;
|
||||
|
||||
/**
|
||||
* @property {number} index - The index of this tile type in the core map data.
|
||||
*/
|
||||
this.index = index;
|
||||
|
||||
/**
|
||||
* @property {number} width - The width of the tile.
|
||||
*/
|
||||
this.width = width;
|
||||
|
||||
/**
|
||||
* @property {number} height - The height of the tile.
|
||||
*/
|
||||
this.height = height;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Tile.prototype = {
|
||||
|
||||
/**
|
||||
/**
|
||||
* Clean up memory.
|
||||
* @method destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
this.tilemap = null;
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set collision configs.
|
||||
* @param collision {number} Bit field of flags. (see Tile.allowCollision)
|
||||
* @param resetCollisions {bool} Reset collision flags before set.
|
||||
* @param separateX {bool} Enable seprate at x-axis.
|
||||
* @param separateY {bool} Enable seprate at y-axis.
|
||||
* @method setCollision
|
||||
* @param {bool} left - Indicating collide with any object on the left.
|
||||
* @param {bool} right - Indicating collide with any object on the right.
|
||||
* @param {bool} up - Indicating collide with any object on the top.
|
||||
* @param {bool} down - Indicating collide with any object on the bottom.
|
||||
* @param {bool} reset - Description.
|
||||
* @param {bool} separateX - Separate at x-axis.
|
||||
* @param {bool} separateY - Separate at y-axis.
|
||||
*/
|
||||
setCollision: function (left, right, up, down, reset, separateX, separateY) {
|
||||
|
||||
@@ -110,8 +139,9 @@ Phaser.Tile.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Reset collision status flags.
|
||||
* @method resetCollision
|
||||
*/
|
||||
resetCollision: function () {
|
||||
|
||||
|
||||
+135
-61
@@ -1,21 +1,24 @@
|
||||
/**
|
||||
* Phaser - Tilemap
|
||||
*
|
||||
* This GameObject allows for the display of a tilemap within the game world. Tile maps consist of an image, tile data and a size.
|
||||
* Internally it creates a TilemapLayer for each layer in the tilemap.
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
* @module Phaser.Tilemap
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Tilemap constructor
|
||||
* Create a new <code>Tilemap</code>.
|
||||
*
|
||||
* @param game {Phaser.Game} Current game instance.
|
||||
* @param key {string} Asset key for this map.
|
||||
* @param mapData {string} Data of this map. (a big 2d array, normally in csv)
|
||||
* @param format {number} Format of this map data, available: Tilemap.CSV or Tilemap.JSON.
|
||||
* @param resizeWorld {bool} Resize the world bound automatically based on this tilemap?
|
||||
* @param tileWidth {number} Width of tiles in this map (used for CSV maps).
|
||||
* @param tileHeight {number} Height of tiles in this map (used for CSV maps).
|
||||
* @class Phaser.Tilemap
|
||||
* @classdesc This GameObject allows for the display of a tilemap within the game world. Tile maps consist of an image, tile data and a size.
|
||||
* Internally it creates a TilemapLayer for each layer in the tilemap.
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - Current game instance.
|
||||
* @param {string} key - Asset key for this map.
|
||||
* @param {object} x - Description.
|
||||
* @param {object} y - Description.
|
||||
* @param {bool} resizeWorld - Resize the world bound automatically based on this tilemap?
|
||||
* @param {number} tileWidth - Width of tiles in this map (used for CSV maps).
|
||||
* @param {number} tileHeight - Height of tiles in this map (used for CSV maps).
|
||||
*/
|
||||
Phaser.Tilemap = function (game, key, x, y, resizeWorld, tileWidth, tileHeight) {
|
||||
|
||||
@@ -23,38 +26,85 @@ Phaser.Tilemap = function (game, key, x, y, resizeWorld, tileWidth, tileHeight)
|
||||
if (typeof tileWidth === "undefined") { tileWidth = 0; }
|
||||
if (typeof tileHeight === "undefined") { tileHeight = 0; }
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Description} group - Description.
|
||||
*/
|
||||
this.group = null;
|
||||
|
||||
/**
|
||||
* @property {string} name - The user defined name given to this Description.
|
||||
* @default
|
||||
*/
|
||||
this.name = '';
|
||||
|
||||
/**
|
||||
* @property {Description} key - Description.
|
||||
*/
|
||||
this.key = key;
|
||||
|
||||
/**
|
||||
* Render iteration counter
|
||||
* @property {number} renderOrderID - Render iteration counter
|
||||
* @default
|
||||
*/
|
||||
this.renderOrderID = 0;
|
||||
|
||||
/**
|
||||
* Tilemap collision callback.
|
||||
* @type {function}
|
||||
*/
|
||||
/**
|
||||
* @property {bool} collisionCallback - Tilemap collision callback.
|
||||
* @default
|
||||
*/
|
||||
this.collisionCallback = null;
|
||||
|
||||
/**
|
||||
* @property {bool} exists - Description.
|
||||
* @default
|
||||
*/
|
||||
this.exists = true;
|
||||
|
||||
/**
|
||||
* @property {bool} visible - Description.
|
||||
* @default
|
||||
*/
|
||||
this.visible = true;
|
||||
|
||||
/**
|
||||
* @property {bool} tiles - Description.
|
||||
* @default
|
||||
*/
|
||||
this.tiles = [];
|
||||
|
||||
/**
|
||||
* @property {bool} layers - Description.
|
||||
* @default
|
||||
*/
|
||||
this.layers = [];
|
||||
|
||||
var map = this.game.cache.getTilemap(key);
|
||||
|
||||
PIXI.DisplayObjectContainer.call(this);
|
||||
/**
|
||||
* @property {Description} position - Description.
|
||||
*/
|
||||
this.position.x = x;
|
||||
this.position.y = y;
|
||||
|
||||
/**
|
||||
* @property {Description} type - Description.
|
||||
*/
|
||||
this.type = Phaser.TILEMAP;
|
||||
|
||||
/**
|
||||
* @property {Description} renderer - Description.
|
||||
*/
|
||||
this.renderer = new Phaser.TilemapRenderer(this.game);
|
||||
|
||||
/**
|
||||
* @property {Description} mapFormat - Description.
|
||||
*/
|
||||
this.mapFormat = map.format;
|
||||
|
||||
switch (this.mapFormat)
|
||||
@@ -83,11 +133,13 @@ Phaser.Tilemap.CSV = 0;
|
||||
Phaser.Tilemap.JSON = 1;
|
||||
|
||||
/**
|
||||
* Parset csv map data and generate tiles.
|
||||
* @param data {string} CSV map data.
|
||||
* @param key {string} Asset key for tileset image.
|
||||
* @param tileWidth {number} Width of its tile.
|
||||
* @param tileHeight {number} Height of its tile.
|
||||
* Parse csv map data and generate tiles.
|
||||
*
|
||||
* @method Phaser.Tilemap.prototype.parseCSV
|
||||
* @param {string} data - CSV map data.
|
||||
* @param {string} key - Asset key for tileset image.
|
||||
* @param {number} tileWidth - Width of its tile.
|
||||
* @param {number} tileHeight - Height of its tile.
|
||||
*/
|
||||
Phaser.Tilemap.prototype.parseCSV = function (data, key, tileWidth, tileHeight) {
|
||||
|
||||
@@ -123,8 +175,10 @@ Phaser.Tilemap.prototype.parseCSV = function (data, key, tileWidth, tileHeight)
|
||||
|
||||
/**
|
||||
* Parse JSON map data and generate tiles.
|
||||
* @param data {string} JSON map data.
|
||||
* @param key {string} Asset key for tileset image.
|
||||
*
|
||||
* @method Phaser.Tilemap.prototype.parseTiledJSON
|
||||
* @param {string} data - JSON map data.
|
||||
* @param {string} key - Asset key for tileset image.
|
||||
*/
|
||||
Phaser.Tilemap.prototype.parseTiledJSON = function (json, key) {
|
||||
|
||||
@@ -181,7 +235,8 @@ Phaser.Tilemap.prototype.parseTiledJSON = function (json, key) {
|
||||
|
||||
/**
|
||||
* Create tiles of given quantity.
|
||||
* @param qty {number} Quentity of tiles to be generated.
|
||||
* @method Phaser.Tilemap.prototype.generateTiles
|
||||
* @param {number} qty - Quantity of tiles to be generated.
|
||||
*/
|
||||
Phaser.Tilemap.prototype.generateTiles = function (qty) {
|
||||
|
||||
@@ -194,8 +249,10 @@ Phaser.Tilemap.prototype.generateTiles = function (qty) {
|
||||
|
||||
/**
|
||||
* Set callback to be called when this tilemap collides.
|
||||
* @param context {object} Callback will be called with this context.
|
||||
* @param callback {function} Callback function.
|
||||
*
|
||||
* @method Phaser.Tilemap.prototype.setCollisionCallback
|
||||
* @param {object} context - Callback will be called with this context.
|
||||
* @param {Function} callback - Callback function.
|
||||
*/
|
||||
Phaser.Tilemap.prototype.setCollisionCallback = function (context, callback) {
|
||||
|
||||
@@ -206,12 +263,14 @@ Phaser.Tilemap.prototype.setCollisionCallback = function (context, callback) {
|
||||
|
||||
/**
|
||||
* Set collision configs of tiles in a range index.
|
||||
* @param start {number} First index of tiles.
|
||||
* @param end {number} Last index of tiles.
|
||||
* @param collision {number} Bit field of flags. (see Tile.allowCollision)
|
||||
* @param resetCollisions {bool} Reset collision flags before set.
|
||||
* @param separateX {bool} Enable seprate at x-axis.
|
||||
* @param separateY {bool} Enable seprate at y-axis.
|
||||
*
|
||||
* @method Phaser.Tilemap.prototype.setCollisionRange
|
||||
* @param {number} start - First index of tiles.
|
||||
* @param {number} end - Last index of tiles.
|
||||
* @param {number} collision - Bit field of flags. (see Tile.allowCollision)
|
||||
* @param {bool} resetCollisions - Reset collision flags before set.
|
||||
* @param {bool} separateX - Enable separate at x-axis.
|
||||
* @param {bool} separateY - Enable separate at y-axis.
|
||||
*/
|
||||
Phaser.Tilemap.prototype.setCollisionRange = function (start, end, left, right, up, down, resetCollisions, separateX, separateY) {
|
||||
|
||||
@@ -228,11 +287,15 @@ Phaser.Tilemap.prototype.setCollisionRange = function (start, end, left, right,
|
||||
|
||||
/**
|
||||
* Set collision configs of tiles with given index.
|
||||
* @param values {number[]} Index array which contains all tile indexes. The tiles with those indexes will be setup with rest parameters.
|
||||
* @param collision {number} Bit field of flags. (see Tile.allowCollision)
|
||||
* @param resetCollisions {bool} Reset collision flags before set.
|
||||
* @param separateX {bool} Enable seprate at x-axis.
|
||||
* @param separateY {bool} Enable seprate at y-axis.
|
||||
* @param {number[]} values - Index array which contains all tile indexes. The tiles with those indexes will be setup with rest parameters.
|
||||
* @param {number} collision - Bit field of flags (see Tile.allowCollision).
|
||||
* @param {bool} resetCollisions - Reset collision flags before set.
|
||||
* @param {bool} left - Indicating collide with any object on the left.
|
||||
* @param {bool} right - Indicating collide with any object on the right.
|
||||
* @param {bool} up - Indicating collide with any object on the top.
|
||||
* @param {bool} down - Indicating collide with any object on the bottom.
|
||||
* @param {bool} separateX - Enable separate at x-axis.
|
||||
* @param {bool} separateY - Enable separate at y-axis.
|
||||
*/
|
||||
Phaser.Tilemap.prototype.setCollisionByIndex = function (values, left, right, up, down, resetCollisions, separateX, separateY) {
|
||||
|
||||
@@ -251,7 +314,7 @@ Phaser.Tilemap.prototype.setCollisionByIndex = function (values, left, right, up
|
||||
|
||||
/**
|
||||
* Get the tile by its index.
|
||||
* @param value {number} Index of the tile you want to get.
|
||||
* @param {number} value - Index of the tile you want to get.
|
||||
* @return {Tile} The tile with given index.
|
||||
*/
|
||||
Phaser.Tilemap.prototype.getTileByIndex = function (value) {
|
||||
@@ -267,9 +330,9 @@ Phaser.Tilemap.prototype.getTileByIndex = function (value) {
|
||||
|
||||
/**
|
||||
* Get the tile located at specific position and layer.
|
||||
* @param x {number} X position of this tile located.
|
||||
* @param y {number} Y position of this tile located.
|
||||
* @param [layer] {number} layer of this tile located.
|
||||
* @param {number} x - X position of this tile located.
|
||||
* @param {number} y - Y position of this tile located.
|
||||
* @param {number} [layer] - layer of this tile located.
|
||||
* @return {Tile} The tile with specific properties.
|
||||
*/
|
||||
Phaser.Tilemap.prototype.getTile = function (x, y, layer) {
|
||||
@@ -281,10 +344,10 @@ Phaser.Tilemap.prototype.getTile = function (x, y, layer) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the tile located at specific position (in world coordinate) and layer. (thus you give a position of a point which is within the tile)
|
||||
* @param x {number} X position of the point in target tile.
|
||||
* @param x {number} Y position of the point in target tile.
|
||||
* @param [layer] {number} layer of this tile located.
|
||||
* Get the tile located at specific position (in world coordinate) and layer (thus you give a position of a point which is within the tile).
|
||||
* @param {number} x - X position of the point in target tile.
|
||||
* @param {number} y - Y position of the point in target tile.
|
||||
* @param {number} [layer] - layer of this tile located.
|
||||
* @return {Tile} The tile with specific properties.
|
||||
*/
|
||||
Phaser.Tilemap.prototype.getTileFromWorldXY = function (x, y, layer) {
|
||||
@@ -296,9 +359,9 @@ Phaser.Tilemap.prototype.getTileFromWorldXY = function (x, y, layer) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the tile underneath the Input.x/y position
|
||||
* @param layer The layer to check, defaults to 0
|
||||
* @returns {Tile}
|
||||
* Gets the tile underneath the Input.x/y position.
|
||||
* @param {number} layer - The layer to check, defaults to 0.
|
||||
* @return {Tile}
|
||||
*/
|
||||
Phaser.Tilemap.prototype.getTileFromInputXY = function (layer) {
|
||||
|
||||
@@ -310,8 +373,8 @@ Phaser.Tilemap.prototype.getTileFromInputXY = function (layer) {
|
||||
|
||||
/**
|
||||
* Get tiles overlaps the given object.
|
||||
* @param object {GameObject} Tiles you want to get that overlaps this.
|
||||
* @return {array} Array with tiles information. (Each contains x, y and the tile.)
|
||||
* @param {GameObject} object - Tiles you want to get that overlaps this.
|
||||
* @return {array} Array with tiles information (Each contains x, y and the tile).
|
||||
*/
|
||||
Phaser.Tilemap.prototype.getTileOverlaps = function (object) {
|
||||
|
||||
@@ -323,9 +386,9 @@ Phaser.Tilemap.prototype.getTileOverlaps = function (object) {
|
||||
|
||||
/**
|
||||
* Check whether this tilemap collides with the given game object or group of objects.
|
||||
* @param objectOrGroup {function} Target object of group you want to check.
|
||||
* @param callback {function} This is called if objectOrGroup collides the tilemap.
|
||||
* @param context {object} Callback will be called with this context.
|
||||
* @param {Function} objectOrGroup - Target object of group you want to check.
|
||||
* @param {Function} callback - This is called if objectOrGroup collides the tilemap.
|
||||
* @param {object} context - Callback will be called with this context.
|
||||
* @return {bool} Return true if this collides with given object, otherwise return false.
|
||||
*/
|
||||
Phaser.Tilemap.prototype.collide = function (objectOrGroup, callback, context) {
|
||||
@@ -353,7 +416,7 @@ Phaser.Tilemap.prototype.collide = function (objectOrGroup, callback, context) {
|
||||
|
||||
/**
|
||||
* Check whether this tilemap collides with the given game object.
|
||||
* @param object {GameObject} Target object you want to check.
|
||||
* @param {GameObject} object - Target object you want to check.
|
||||
* @return {bool} Return true if this collides with given object, otherwise return false.
|
||||
*/
|
||||
Phaser.Tilemap.prototype.collideGameObject = function (object) {
|
||||
@@ -383,10 +446,10 @@ Phaser.Tilemap.prototype.collideGameObject = function (object) {
|
||||
|
||||
/**
|
||||
* Set a tile to a specific layer.
|
||||
* @param x {number} X position of this tile.
|
||||
* @param y {number} Y position of this tile.
|
||||
* @param index {number} The index of this tile type in the core map data.
|
||||
* @param [layer] {number} which layer you want to set the tile to.
|
||||
* @param {number} x - X position of this tile.
|
||||
* @param {number} y - Y position of this tile.
|
||||
* @param {number} index - The index of this tile type in the core map data.
|
||||
* @param {number} [layer] - Which layer you want to set the tile to.
|
||||
*/
|
||||
Phaser.Tilemap.prototype.putTile = function (x, y, index, layer) {
|
||||
|
||||
@@ -397,7 +460,7 @@ Phaser.Tilemap.prototype.putTile = function (x, y, index, layer) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Calls the renderer
|
||||
* Calls the renderer.
|
||||
*/
|
||||
Phaser.Tilemap.prototype.update = function () {
|
||||
|
||||
@@ -405,6 +468,9 @@ Phaser.Tilemap.prototype.update = function () {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Description.
|
||||
*/
|
||||
Phaser.Tilemap.prototype.destroy = function () {
|
||||
|
||||
this.tiles.length = 0;
|
||||
@@ -412,6 +478,10 @@ Phaser.Tilemap.prototype.destroy = function () {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Get width in pixels.
|
||||
* @return {number}
|
||||
*/
|
||||
Object.defineProperty(Phaser.Tilemap.prototype, "widthInPixels", {
|
||||
|
||||
get: function () {
|
||||
@@ -420,6 +490,10 @@ Object.defineProperty(Phaser.Tilemap.prototype, "widthInPixels", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get height in pixels.
|
||||
* @return {number}
|
||||
*/
|
||||
Object.defineProperty(Phaser.Tilemap.prototype, "heightInPixels", {
|
||||
|
||||
get: function () {
|
||||
|
||||
+196
-82
@@ -1,113 +1,203 @@
|
||||
/**
|
||||
* Phaser - TilemapLayer
|
||||
*
|
||||
* A Tilemap Layer. Tiled format maps can have multiple overlapping layers.
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
* @module Phaser.TilemapLayer
|
||||
*/
|
||||
|
||||
/**
|
||||
* TilemapLayer constructor
|
||||
* Create a new <code>TilemapLayer</code>.
|
||||
*
|
||||
* @class Phaser.TilemapLayer
|
||||
* @classdesc A Tilemap Layer. Tiled format maps can have multiple overlapping layers.
|
||||
* @constructor
|
||||
* @param parent {Tilemap} The tilemap that contains this layer.
|
||||
* @param id {number} The ID of this layer within the Tilemap array.
|
||||
* @param key {string} Asset key for this map.
|
||||
* @param mapFormat {number} Format of this map data, available: Tilemap.CSV or Tilemap.JSON.
|
||||
* @param mapformat {number} Format of this map data, available: Tilemap.CSV or Tilemap.JSON.
|
||||
* @param name {string} Name of this layer, so you can get this layer by its name.
|
||||
* @param tileWidth {number} Width of tiles in this map.
|
||||
* @param tileHeight {number} Height of tiles in this map.
|
||||
*/
|
||||
Phaser.TilemapLayer = function (parent, id, key, mapFormat, name, tileWidth, tileHeight) {
|
||||
|
||||
/**
|
||||
* Controls whether update() and draw() are automatically called.
|
||||
* @type {bool}
|
||||
*/
|
||||
/**
|
||||
* @property {bool} exists - Controls whether update() and draw() are automatically called.
|
||||
* @default
|
||||
*/
|
||||
this.exists = true;
|
||||
|
||||
/**
|
||||
* Controls whether draw() are automatically called.
|
||||
* @type {bool}
|
||||
*/
|
||||
/**
|
||||
* @property {bool} visible - Controls whether draw() are automatically called.
|
||||
* @default
|
||||
*/
|
||||
this.visible = true;
|
||||
|
||||
/**
|
||||
* How many tiles in each row.
|
||||
* Read-only variable, do NOT recommend changing after the map is loaded!
|
||||
* @type {number}
|
||||
* @property {number} widthInTiles
|
||||
* @default
|
||||
*/
|
||||
this.widthInTiles = 0;
|
||||
|
||||
/**
|
||||
* How many tiles in each column.
|
||||
* Read-only variable, do NOT recommend changing after the map is loaded!
|
||||
* @type {number}
|
||||
* @property {number} heightInTiles
|
||||
* @default
|
||||
*/
|
||||
this.heightInTiles = 0;
|
||||
|
||||
/**
|
||||
* Read-only variable, do NOT recommend changing after the map is loaded!
|
||||
* @type {number}
|
||||
* @property {number} widthInPixels
|
||||
* @default
|
||||
*/
|
||||
this.widthInPixels = 0;
|
||||
|
||||
/**
|
||||
* Read-only variable, do NOT recommend changing after the map is loaded!
|
||||
* @type {number}
|
||||
* @property {number} heightInPixels
|
||||
* @default
|
||||
*/
|
||||
this.heightInPixels = 0;
|
||||
|
||||
/**
|
||||
* Distance between REAL tiles to the tileset texture bound.
|
||||
* @type {number}
|
||||
* @property {number} tileMargin
|
||||
* @default
|
||||
*/
|
||||
this.tileMargin = 0;
|
||||
|
||||
/**
|
||||
* Distance between every 2 neighbor tile in the tileset texture.
|
||||
* @type {number}
|
||||
* @property {number} tileSpacing
|
||||
* @default
|
||||
*/
|
||||
this.tileSpacing = 0;
|
||||
|
||||
/**
|
||||
* @property {Description} parent - Description.
|
||||
*/
|
||||
this.parent = parent;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - Description.
|
||||
*/
|
||||
this.game = parent.game;
|
||||
|
||||
/**
|
||||
* @property {Description} ID - Description.
|
||||
*/
|
||||
this.ID = id;
|
||||
|
||||
/**
|
||||
* @property {Description} name - Description.
|
||||
*/
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* @property {Description} key - Description.
|
||||
*/
|
||||
this.key = key;
|
||||
|
||||
/**
|
||||
* @property {Description} type - Description.
|
||||
*/
|
||||
this.type = Phaser.TILEMAPLAYER;
|
||||
|
||||
/**
|
||||
* @property {tileWidth} mapFormat - Description.
|
||||
*/
|
||||
this.mapFormat = mapFormat;
|
||||
|
||||
/**
|
||||
* @property {Description} tileWidth - Description.
|
||||
*/
|
||||
this.tileWidth = tileWidth;
|
||||
|
||||
/**
|
||||
* @property {Description} tileHeight - Description.
|
||||
*/
|
||||
this.tileHeight = tileHeight;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Rectangle} boundsInTiles - Description.
|
||||
*/
|
||||
this.boundsInTiles = new Phaser.Rectangle();
|
||||
|
||||
var map = this.game.cache.getTilemap(key);
|
||||
|
||||
/**
|
||||
* @property {Description} tileset - Description.
|
||||
*/
|
||||
this.tileset = map.data;
|
||||
|
||||
/**
|
||||
* @property {Description} _alpha - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._alpha = 1;
|
||||
|
||||
this.quadTree = null;
|
||||
|
||||
/**
|
||||
* @property {Description} canvas - Description.
|
||||
* @default
|
||||
*/
|
||||
this.canvas = null;
|
||||
|
||||
/**
|
||||
* @property {Description} context - Description.
|
||||
* @default
|
||||
*/
|
||||
this.context = null;
|
||||
|
||||
/**
|
||||
* @property {Description} baseTexture - Description.
|
||||
* @default
|
||||
*/
|
||||
this.baseTexture = null;
|
||||
|
||||
/**
|
||||
* @property {Description} texture - Description.
|
||||
* @default
|
||||
*/
|
||||
this.texture = null;
|
||||
|
||||
/**
|
||||
* @property {Description} sprite - Description.
|
||||
* @default
|
||||
*/
|
||||
this.sprite = null;
|
||||
|
||||
/**
|
||||
* @property {array} mapData - Description.
|
||||
*/
|
||||
this.mapData = [];
|
||||
|
||||
/**
|
||||
* @property {array} _tempTileBlock - Description.
|
||||
* @private
|
||||
*/
|
||||
this._tempTileBlock = [];
|
||||
|
||||
/**
|
||||
* @property {array} _tempBlockResults - Description.
|
||||
* @private
|
||||
*
|
||||
*/
|
||||
this._tempBlockResults = [];
|
||||
|
||||
};
|
||||
|
||||
Phaser.TilemapLayer.prototype = {
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set a specific tile with its x and y in tiles.
|
||||
* @param x {number} X position of this tile in world coordinates.
|
||||
* @param y {number} Y position of this tile in world coordinates.
|
||||
* @param index {number} The index of this tile type in the core map data.
|
||||
* @method putTileWorldXY
|
||||
* @param {number} x - X position of this tile in world coordinates.
|
||||
* @param {number} y - Y position of this tile in world coordinates.
|
||||
* @param {number} index - The index of this tile type in the core map data.
|
||||
*/
|
||||
putTileWorldXY: function (x, y, index) {
|
||||
|
||||
@@ -124,11 +214,12 @@ Phaser.TilemapLayer.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set a specific tile with its x and y in tiles.
|
||||
* @param x {number} X position of this tile.
|
||||
* @param y {number} Y position of this tile.
|
||||
* @param index {number} The index of this tile type in the core map data.
|
||||
* @method putTile
|
||||
* @param {number} x - X position of this tile.
|
||||
* @param {number} y - Y position of this tile.
|
||||
* @param {number} index - The index of this tile type in the core map data.
|
||||
*/
|
||||
putTile: function (x, y, index) {
|
||||
|
||||
@@ -142,14 +233,15 @@ Phaser.TilemapLayer.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Swap tiles with 2 kinds of indexes.
|
||||
* @param tileA {number} First tile index.
|
||||
* @param tileB {number} Second tile index.
|
||||
* @param [x] {number} specify a Rectangle of tiles to operate. The x position in tiles of Rectangle's left-top corner.
|
||||
* @param [y] {number} specify a Rectangle of tiles to operate. The y position in tiles of Rectangle's left-top corner.
|
||||
* @param [width] {number} specify a Rectangle of tiles to operate. The width in tiles.
|
||||
* @param [height] {number} specify a Rectangle of tiles to operate. The height in tiles.
|
||||
* @method swapTile
|
||||
* @param {number} tileA - First tile index.
|
||||
* @param {number} tileB - Second tile index.
|
||||
* @param {number} [x] - specify a Rectangle of tiles to operate. The x position in tiles of Rectangle's left-top corner.
|
||||
* @param {number} [y] - specify a Rectangle of tiles to operate. The y position in tiles of Rectangle's left-top corner.
|
||||
* @param {number} [width] - specify a Rectangle of tiles to operate. The width in tiles.
|
||||
* @param {number} [height] - specify a Rectangle of tiles to operate. The height in tiles.
|
||||
*/
|
||||
swapTile: function (tileA, tileB, x, y, width, height) {
|
||||
|
||||
@@ -186,13 +278,14 @@ Phaser.TilemapLayer.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Fill a tile block with a specific tile index.
|
||||
* @param index {number} Index of tiles you want to fill with.
|
||||
* @param [x] {number} x position (in tiles) of block's left-top corner.
|
||||
* @param [y] {number} y position (in tiles) of block's left-top corner.
|
||||
* @param [width] {number} width of block.
|
||||
* @param [height] {number} height of block.
|
||||
* @method fillTile
|
||||
* @param {number} index - Index of tiles you want to fill with.
|
||||
* @param {number} [x] - X position (in tiles) of block's left-top corner.
|
||||
* @param {number} [y] - Y position (in tiles) of block's left-top corner.
|
||||
* @param {number} [width] - width of block.
|
||||
* @param {number} [height] - height of block.
|
||||
*/
|
||||
fillTile: function (index, x, y, width, height) {
|
||||
|
||||
@@ -210,13 +303,14 @@ Phaser.TilemapLayer.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set random tiles to a specific tile block.
|
||||
* @param tiles {number[]} Tiles with indexes in this array will be randomly set to the given block.
|
||||
* @param [x] {number} x position (in tiles) of block's left-top corner.
|
||||
* @param [y] {number} y position (in tiles) of block's left-top corner.
|
||||
* @param [width] {number} width of block.
|
||||
* @param [height] {number} height of block.
|
||||
* @method randomiseTiles
|
||||
* @param {number[]} tiles - Tiles with indexes in this array will be randomly set to the given block.
|
||||
* @param {number} [x] - X position (in tiles) of block's left-top corner.
|
||||
* @param {number} [y] - Y position (in tiles) of block's left-top corner.
|
||||
* @param {number} [width] - width of block.
|
||||
* @param {number} [height] - height of block.
|
||||
*/
|
||||
randomiseTiles: function (tiles, x, y, width, height) {
|
||||
|
||||
@@ -234,14 +328,15 @@ Phaser.TilemapLayer.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Replace one kind of tiles to another kind.
|
||||
* @param tileA {number} Index of tiles you want to replace.
|
||||
* @param tileB {number} Index of tiles you want to set.
|
||||
* @param [x] {number} x position (in tiles) of block's left-top corner.
|
||||
* @param [y] {number} y position (in tiles) of block's left-top corner.
|
||||
* @param [width] {number} width of block.
|
||||
* @param [height] {number} height of block.
|
||||
* @method replaceTile
|
||||
* @param {number} tileA - First tile index.
|
||||
* @param {number} tileB - Second tile index.
|
||||
* @param {number} [x] - X position (in tiles) of block's left-top corner.
|
||||
* @param {number} [y] - Y position (in tiles) of block's left-top corner.
|
||||
* @param {number} [width] - width of block.
|
||||
* @param {number} [height] - height of block.
|
||||
*/
|
||||
replaceTile: function (tileA, tileB, x, y, width, height) {
|
||||
|
||||
@@ -262,12 +357,13 @@ Phaser.TilemapLayer.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a tile block with specific position and size.(both are in tiles)
|
||||
* @param x {number} X position of block's left-top corner.
|
||||
* @param y {number} Y position of block's left-top corner.
|
||||
* @param width {number} Width of block.
|
||||
* @param height {number} Height of block.
|
||||
/**
|
||||
* Get a tile block with specific position and size (both are in tiles).
|
||||
* @method getTileBlock
|
||||
* @param {number} [x] - X position (in tiles) of block's left-top corner.
|
||||
* @param {number} [y] - Y position (in tiles) of block's left-top corner.
|
||||
* @param {number} [width] - width of block.
|
||||
* @param {number} [height] - height of block.
|
||||
*/
|
||||
getTileBlock: function (x, y, width, height) {
|
||||
|
||||
@@ -288,10 +384,11 @@ Phaser.TilemapLayer.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get a tile with specific position (in world coordinate). (thus you give a position of a point which is within the tile)
|
||||
* @param x {number} X position of the point in target tile.
|
||||
* @param x {number} Y position of the point in target tile.
|
||||
* @method getTileFromWorldXY
|
||||
* @param {number} [x] - X position (in tiles) of block's left-top corner.
|
||||
* @param {number} [y] - Y position (in tiles) of block's left-top corner.
|
||||
*/
|
||||
getTileFromWorldXY: function (x, y) {
|
||||
|
||||
@@ -302,10 +399,11 @@ Phaser.TilemapLayer.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get tiles overlaps the given object.
|
||||
* @param object {GameObject} Tiles you want to get that overlaps this.
|
||||
* @return {array} Array with tiles informations. (Each contains x, y and the tile.)
|
||||
* @method getTileOverlaps
|
||||
* @param {GameObject} object - Tiles you want to get that overlaps this.
|
||||
* @return {array} Array with tiles informations (each contains x, y, and the tile).
|
||||
*/
|
||||
getTileOverlaps: function (object) {
|
||||
|
||||
@@ -339,13 +437,14 @@ Phaser.TilemapLayer.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get a tile block with its position and size. (This method does not return, it'll set result to _tempTileBlock)
|
||||
* @param x {number} X position of block's left-top corner.
|
||||
* @param y {number} Y position of block's left-top corner.
|
||||
* @param width {number} Width of block.
|
||||
* @param height {number} Height of block.
|
||||
* @param collisionOnly {bool} Whethor or not ONLY return tiles which will collide (its allowCollisions value is not Collision.NONE).
|
||||
/**
|
||||
* Get a tile block with its position and size (this method does not return, it'll set result to _tempTileBlock).
|
||||
* @method getTempBlock
|
||||
* @param {number} [x] - X position (in tiles) of block's left-top corner.
|
||||
* @param {number} [y] - Y position (in tiles) of block's left-top corner.
|
||||
* @param {number} [width] - width of block.
|
||||
* @param {number} [height] - height of block.
|
||||
* @param {bool} collisionOnly - Whethor or not ONLY return tiles which will collide (its allowCollisions value is not Collision.NONE).
|
||||
*/
|
||||
getTempBlock: function (x, y, width, height, collisionOnly) {
|
||||
|
||||
@@ -404,10 +503,11 @@ Phaser.TilemapLayer.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get the tile index of specific position (in tiles).
|
||||
* @param x {number} X position of the tile.
|
||||
* @param y {number} Y position of the tile.
|
||||
* @method getTileIndex
|
||||
* @param {number} x - X position of the tile.
|
||||
* @param {number} y - Y position of the tile.
|
||||
* @return {number} Index of the tile at that position. Return null if there isn't a tile there.
|
||||
*/
|
||||
getTileIndex: function (x, y) {
|
||||
@@ -424,9 +524,10 @@ Phaser.TilemapLayer.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add a column of tiles into the layer.
|
||||
* @param column {string[]/number[]} An array of tile indexes to be added.
|
||||
* @method addColumn
|
||||
* @param {string[]|number[]} column - An array of tile indexes to be added.
|
||||
*/
|
||||
addColumn: function (column) {
|
||||
|
||||
@@ -450,6 +551,10 @@ Phaser.TilemapLayer.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method createCanvas
|
||||
*/
|
||||
createCanvas: function () {
|
||||
|
||||
var width = this.game.width;
|
||||
@@ -484,6 +589,7 @@ Phaser.TilemapLayer.prototype = {
|
||||
|
||||
/**
|
||||
* Update boundsInTiles with widthInTiles and heightInTiles.
|
||||
* @method updateBounds
|
||||
*/
|
||||
updateBounds: function () {
|
||||
|
||||
@@ -491,12 +597,13 @@ Phaser.TilemapLayer.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Parse tile offsets from map data.
|
||||
* Basically this creates a large array of objects that contain the x/y coordinates to grab each tile from
|
||||
* for the entire map. Yes we could calculate this at run-time by using the tile index and some math, but we're
|
||||
* trading a quite small bit of memory here to not have to process that in our main render loop.
|
||||
* @return {number} length of tileOffsets array.
|
||||
* @method parseTileOffsets
|
||||
* @return {number} Length of tileOffsets array.
|
||||
*/
|
||||
parseTileOffsets: function () {
|
||||
|
||||
@@ -529,6 +636,13 @@ Phaser.TilemapLayer.prototype = {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Get
|
||||
* @return {Description}
|
||||
*//**
|
||||
* Set
|
||||
* @param {Description} value - Description.
|
||||
*/
|
||||
Object.defineProperty(Phaser.TilemapLayer.prototype, 'alpha', {
|
||||
|
||||
get: function() {
|
||||
|
||||
@@ -1,19 +1,106 @@
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
* @module Phaser.TilemapRenderer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tilemap renderer.
|
||||
*
|
||||
* @class Phaser.TilemapRenderer
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
Phaser.TilemapRenderer = function (game) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
// Local rendering related temp vars to help avoid gc spikes through constant var creation
|
||||
|
||||
/**
|
||||
* @property {number} _ga - Local rendering related temp vars to help avoid gc spikes through constant var creation.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._ga = 1;
|
||||
|
||||
/**
|
||||
* @property {number} _dx - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._dx = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _dy - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._dy = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _dw - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._dw = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _dh - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._dh = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _tx - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._tx = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _ty - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._ty = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _tl - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._tl = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _maxX - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._maxX = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _maxY - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._maxY = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _startX - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._startX = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _startY - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._startY = 0;
|
||||
|
||||
};
|
||||
@@ -21,9 +108,11 @@ Phaser.TilemapRenderer = function (game) {
|
||||
Phaser.TilemapRenderer.prototype = {
|
||||
|
||||
/**
|
||||
* Render a tilemap to a canvas.
|
||||
* @param tilemap {Tilemap} The tilemap data to render.
|
||||
*/
|
||||
* Render a tilemap to a canvas.
|
||||
* @method render
|
||||
* @param tilemap {Tilemap} The tilemap data to render.
|
||||
* @return {bool} Description.
|
||||
*/
|
||||
render: function (tilemap) {
|
||||
|
||||
// Loop through the layers
|
||||
|
||||
Reference in New Issue
Block a user