mirror of
https://github.com/wassname/phaser.git
synced 2026-07-29 11:24:31 +08:00
Lots of documentation updates and new Loader examples.
This commit is contained in:
@@ -1,4 +1,21 @@
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Tile set is a combination of an image containing the tiles and collision data per tile.
|
||||
*
|
||||
* @class Phaser.Tileset
|
||||
* @constructor
|
||||
* @param {Image} image - The Image object from the Cache.
|
||||
* @param {string} key - The key of the tileset in the cache.
|
||||
* @param {number} tileWidth - The width of the tile in pixels.
|
||||
* @param {number} tileHeight - The height of the tile in pixels.
|
||||
* @param {number} [tileMargin] - The margin around the tiles in the sheet.
|
||||
* @param {number} [tileSpacing] - The spacing between the tiles in the sheet.
|
||||
*/
|
||||
Phaser.Tileset = function (image, key, tileWidth, tileHeight, tileMargin, tileSpacing) {
|
||||
|
||||
if (typeof tileMargin === "undefined") { tileMargin = 0; }
|
||||
@@ -9,19 +26,46 @@ Phaser.Tileset = function (image, key, tileWidth, tileHeight, tileMargin, tileSp
|
||||
*/
|
||||
this.key = key;
|
||||
|
||||
/**
|
||||
* @property {object} image - The image used for rendering.
|
||||
*/
|
||||
this.image = image;
|
||||
|
||||
/**
|
||||
* @property {number} tileWidth - The width of a tile in pixels.
|
||||
*/
|
||||
this.tileWidth = tileWidth;
|
||||
|
||||
/**
|
||||
* @property {number} tileHeight - The height of a tile in pixels.
|
||||
*/
|
||||
this.tileHeight = tileHeight;
|
||||
|
||||
/**
|
||||
* @property {number} tileMargin - The margin around the tiles in the sheet.
|
||||
*/
|
||||
this.margin = tileMargin;
|
||||
|
||||
/**
|
||||
* @property {number} tileSpacing - The margin around the tiles in the sheet.
|
||||
*/
|
||||
this.spacing = tileSpacing;
|
||||
|
||||
/**
|
||||
* @property {array} tiles - An array of the tile collision data.
|
||||
*/
|
||||
this.tiles = [];
|
||||
|
||||
}
|
||||
|
||||
Phaser.Tileset.prototype = {
|
||||
|
||||
/**
|
||||
* Adds a Tile into this set.
|
||||
*
|
||||
* @method Phaser.Tileset#addTile
|
||||
* @param {Phaser.Tile} tile - The tile to add to this set.
|
||||
*/
|
||||
addTile: function (tile) {
|
||||
|
||||
this.tiles.push(tile);
|
||||
@@ -30,6 +74,13 @@ Phaser.Tileset.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets a Tile from this set.
|
||||
*
|
||||
* @method Phaser.Tileset#getTile
|
||||
* @param {number} index - The index of the tile within the set.
|
||||
* @return {Phaser.Tile} The tile.
|
||||
*/
|
||||
getTile: function (index) {
|
||||
|
||||
if (this.tiles[index])
|
||||
@@ -41,6 +92,13 @@ Phaser.Tileset.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets tile spacing and margins.
|
||||
*
|
||||
* @method Phaser.Tileset#setSpacing
|
||||
* @param {number} [tileMargin] - The margin around the tiles in the sheet.
|
||||
* @param {number} [tileSpacing] - The spacing between the tiles in the sheet.
|
||||
*/
|
||||
setSpacing: function (margin, spacing) {
|
||||
|
||||
this.tileMargin = margin;
|
||||
@@ -48,6 +106,13 @@ Phaser.Tileset.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the tile at the given index can collide.
|
||||
*
|
||||
* @method Phaser.Tileset#canCollide
|
||||
* @param {number} index - The index of the tile within the set.
|
||||
* @return {boolean} True or false depending on the tile collision or null if no tile was found at the given index.
|
||||
*/
|
||||
canCollide: function (index) {
|
||||
|
||||
if (this.tiles[index])
|
||||
@@ -59,12 +124,30 @@ Phaser.Tileset.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the tile at the given index exists.
|
||||
*
|
||||
* @method Phaser.Tileset#checkTileIndex
|
||||
* @param {number} index - The index of the tile within the set.
|
||||
* @return {boolean} True if a tile exists at the given index otherwise false.
|
||||
*/
|
||||
checkTileIndex: function (index) {
|
||||
|
||||
return (this.tiles[index]);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets collision values on a range of tiles in the set.
|
||||
*
|
||||
* @method Phaser.Tileset#setCollisionRange
|
||||
* @param {number} start - The index to start setting the collision data on.
|
||||
* @param {number} stop - The index to stop setting the collision data on.
|
||||
* @param {boolean} left - Should the tile collide on the left?
|
||||
* @param {boolean} right - Should the tile collide on the right?
|
||||
* @param {boolean} up - Should the tile collide on the top?
|
||||
* @param {boolean} down - Should the tile collide on the bottom?
|
||||
*/
|
||||
setCollisionRange: function (start, stop, left, right, up, down) {
|
||||
|
||||
if (this.tiles[start] && this.tiles[stop] && start < stop)
|
||||
@@ -77,6 +160,16 @@ Phaser.Tileset.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets collision values on a tile in the set.
|
||||
*
|
||||
* @method Phaser.Tileset#setCollision
|
||||
* @param {number} index - The index of the tile within the set.
|
||||
* @param {boolean} left - Should the tile collide on the left?
|
||||
* @param {boolean} right - Should the tile collide on the right?
|
||||
* @param {boolean} up - Should the tile collide on the top?
|
||||
* @param {boolean} down - Should the tile collide on the bottom?
|
||||
*/
|
||||
setCollision: function (index, left, right, up, down) {
|
||||
|
||||
if (this.tiles[index])
|
||||
|
||||
Reference in New Issue
Block a user