2013-11-27 16:33:49 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2013 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
2013-10-11 03:42:11 +00:00
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
|
|
|
* A Tile set is a combination of an image containing the tiles and collision data per tile.
|
2013-12-18 00:44:04 +00:00
|
|
|
* You should not normally instantiate this class directly.
|
2013-11-27 16:33:49 +00:00
|
|
|
*
|
|
|
|
* @class Phaser.Tileset
|
|
|
|
* @constructor
|
2013-12-18 16:56:14 +00:00
|
|
|
* @param {string} name - The name of the tileset in the map data.
|
2013-12-19 03:49:28 +00:00
|
|
|
* @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-11-27 16:33:49 +00:00
|
|
|
*/
|
2013-12-18 16:56:14 +00:00
|
|
|
Phaser.Tileset = function (name, firstgid, width, height, margin, spacing, properties) {
|
2013-10-11 03:42:11 +00:00
|
|
|
|
|
|
|
/**
|
2013-12-18 16:56:14 +00:00
|
|
|
* @property {string} name - The name of the Tileset.
|
2013-10-11 03:42:11 +00:00
|
|
|
*/
|
2013-12-18 16:56:14 +00:00
|
|
|
this.name = name;
|
2013-10-11 03:42:11 +00:00
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
2013-12-18 16:56:14 +00:00
|
|
|
* @property {number} firstgid - The Tiled firstgid value.
|
|
|
|
* @default
|
2013-11-27 16:33:49 +00:00
|
|
|
*/
|
2013-12-18 16:56:14 +00:00
|
|
|
this.firstgid = firstgid;
|
2013-10-11 05:30:28 +00:00
|
|
|
|
2013-12-18 00:44:04 +00:00
|
|
|
/**
|
2013-12-18 16:56:14 +00:00
|
|
|
* @property {number} tileWidth - The width of a tile in pixels.
|
2013-12-18 00:44:04 +00:00
|
|
|
*/
|
2013-12-18 16:56:14 +00:00
|
|
|
this.tileWidth = width;
|
2013-12-18 00:44:04 +00:00
|
|
|
|
|
|
|
/**
|
2013-12-18 16:56:14 +00:00
|
|
|
* @property {number} tileHeight - The height of a tile in pixels.
|
2013-12-18 00:44:04 +00:00
|
|
|
*/
|
2013-12-18 16:56:14 +00:00
|
|
|
this.tileHeight = height;
|
2013-12-18 00:44:04 +00:00
|
|
|
|
2013-12-17 05:07:00 +00:00
|
|
|
/**
|
2013-12-18 16:56:14 +00:00
|
|
|
* @property {number} tileMargin - The margin around the tiles in the sheet.
|
2013-12-17 05:07:00 +00:00
|
|
|
*/
|
2013-12-18 16:56:14 +00:00
|
|
|
this.tileMargin = margin;
|
2013-12-17 05:07:00 +00:00
|
|
|
|
|
|
|
/**
|
2013-12-18 16:56:14 +00:00
|
|
|
* @property {number} tileSpacing - The margin around the tiles in the sheet.
|
2013-12-17 05:07:00 +00:00
|
|
|
*/
|
2013-12-18 16:56:14 +00:00
|
|
|
this.tileSpacing = spacing;
|
2013-12-17 05:07:00 +00:00
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
2013-12-18 16:56:14 +00:00
|
|
|
* @property {object} properties - Tileset specific properties (typically defined in the Tiled editor).
|
2013-11-27 16:33:49 +00:00
|
|
|
*/
|
2013-12-18 16:56:14 +00:00
|
|
|
this.properties = properties;
|
2013-11-27 16:33:49 +00:00
|
|
|
|
|
|
|
/**
|
2013-12-18 16:56:14 +00:00
|
|
|
* @property {object} tilePproperties - Tile specific properties (typically defined in the Tiled editor).
|
2013-11-27 16:33:49 +00:00
|
|
|
*/
|
2014-01-15 13:20:51 +00:00
|
|
|
// this.tileProperties = {};
|
2013-11-27 16:33:49 +00:00
|
|
|
|
|
|
|
/**
|
2014-01-15 13:20:51 +00:00
|
|
|
* @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-11-27 16:33:49 +00:00
|
|
|
*/
|
2013-12-18 16:56:14 +00:00
|
|
|
this.total = 0;
|
2013-10-11 03:42:11 +00:00
|
|
|
|
2013-12-30 16:54:00 +00:00
|
|
|
};
|
2013-10-11 03:42:11 +00:00
|
|
|
|
|
|
|
Phaser.Tileset.prototype = {
|
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
|
|
|
* Gets a Tile from this set.
|
|
|
|
*
|
|
|
|
* @method Phaser.Tileset#getTile
|
|
|
|
* @param {number} index - The index of the tile within the set.
|
2013-12-17 05:07:00 +00:00
|
|
|
* @return {object} The tile object.
|
2013-10-11 03:42:11 +00:00
|
|
|
getTile: function (index) {
|
|
|
|
|
2013-12-17 05:07:00 +00:00
|
|
|
return this.tiles[index];
|
2013-10-11 03:42:11 +00:00
|
|
|
|
2013-12-17 05:07:00 +00:00
|
|
|
},
|
2014-01-15 13:20:51 +00:00
|
|
|
*/
|
2013-12-17 05:07:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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];
|
|
|
|
|
|
|
|
},
|
2014-01-15 13:20:51 +00:00
|
|
|
*/
|
2013-12-17 05:07:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 03:42:11 +00:00
|
|
|
|
2013-10-11 05:30:28 +00:00
|
|
|
},
|
2014-01-15 13:20:51 +00:00
|
|
|
*/
|
2013-10-11 05:30:28 +00:00
|
|
|
|
2013-11-27 16:33:49 +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;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
return (this.tiles[index]);
|
2013-10-11 05:30:28 +00:00
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
}
|
2014-01-15 13:20:51 +00:00
|
|
|
*/
|
2013-10-11 03:42:11 +00:00
|
|
|
|
2013-12-30 16:54:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.Tileset.prototype.constructor = Phaser.Tileset;
|