phaser/src/tilemap/Tileset.js

157 lines
4 KiB
JavaScript
Raw Normal View History

/**
* @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.
* You should not normally instantiate this class directly.
*
* @class Phaser.Tileset
* @constructor
2013-12-18 16:56:14 +00:00
* @param {string} name - The name of the tileset in the map data.
* @param {number} firstgid - The Tiled firstgid value.
* @param {number} width - Width of each tile in pixels.
* @param {number} height - Height of each tile in pixels.
* @param {number} margin - The amount of margin around the tilesheet.
* @param {number} spacing - The amount of spacing between each tile in the sheet.
* @param {object} properties - Tileset properties.
*/
2013-12-18 16:56:14 +00:00
Phaser.Tileset = function (name, firstgid, width, height, margin, spacing, properties) {
/**
2013-12-18 16:56:14 +00:00
* @property {string} name - The name of the Tileset.
*/
2013-12-18 16:56:14 +00:00
this.name = name;
/**
2013-12-18 16:56:14 +00:00
* @property {number} firstgid - The Tiled firstgid value.
* @default
*/
2013-12-18 16:56:14 +00:00
this.firstgid = firstgid;
2013-10-11 05:30:28 +00:00
/**
2013-12-18 16:56:14 +00:00
* @property {number} tileWidth - The width of a tile in pixels.
*/
2013-12-18 16:56:14 +00:00
this.tileWidth = width;
/**
2013-12-18 16:56:14 +00:00
* @property {number} tileHeight - The height of a tile in pixels.
*/
2013-12-18 16:56:14 +00:00
this.tileHeight = height;
/**
2013-12-18 16:56:14 +00:00
* @property {number} tileMargin - The margin around the tiles in the sheet.
*/
2013-12-18 16:56:14 +00:00
this.tileMargin = margin;
/**
2013-12-18 16:56:14 +00:00
* @property {number} tileSpacing - The margin around the tiles in the sheet.
*/
2013-12-18 16:56:14 +00:00
this.tileSpacing = spacing;
/**
2013-12-18 16:56:14 +00:00
* @property {object} properties - Tileset specific properties (typically defined in the Tiled editor).
*/
2013-12-18 16:56:14 +00:00
this.properties = properties;
/**
2013-12-18 16:56:14 +00:00
* @property {object} tilePproperties - Tile specific properties (typically defined in the Tiled editor).
*/
// this.tileProperties = {};
/**
* @property {object} image - The image used for rendering. This is a reference to the image stored in Phaser.Cache.
2013-12-18 16:56:14 +00:00
*/
this.image = null;
/**
* @property {number} rows - The number of rows in the tile sheet.
*/
this.rows = 0;
/**
* @property {number} columns - The number of columns in the tile sheet.
*/
this.columns = 0;
/**
* @property {number} total - The total number of tiles in the tilesheet.
*/
2013-12-18 16:56:14 +00:00
this.total = 0;
};
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 {object} The tile object.
getTile: function (index) {
return this.tiles[index];
},
*/
/**
* Gets a Tile from this set.
*
* @method Phaser.Tileset#getTileX
* @param {number} index - The index of the tile within the set.
* @return {object} The tile object.
getTileX: function (index) {
return this.tiles[index][0];
},
*/
/**
* Gets a Tile from this set.
*
* @method Phaser.Tileset#getTileY
* @param {number} index - The index of the tile within the set.
* @return {object} The tile object.
getTileY: function (index) {
return this.tiles[index][1];
2013-10-11 05:30:28 +00:00
},
*/
2013-10-11 05:30:28 +00:00
/**
* 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.
*/
2013-10-16 20:25:51 +00:00
setSpacing: function (margin, spacing) {
this.tileMargin = margin;
this.tileSpacing = spacing;
},
/**
* 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.
2013-10-11 05:30:28 +00:00
checkTileIndex: function (index) {
return (this.tiles[index]);
2013-10-11 05:30:28 +00:00
}
*/
};
Phaser.Tileset.prototype.constructor = Phaser.Tileset;