2013-10-11 03:42:11 +00:00
|
|
|
|
2013-10-16 20:25:51 +00:00
|
|
|
Phaser.Tileset = function (image, key, tileWidth, tileHeight, tileMargin, tileSpacing) {
|
|
|
|
|
|
|
|
if (typeof tileMargin === "undefined") { tileMargin = 0; }
|
|
|
|
if (typeof tileSpacing === "undefined") { tileSpacing = 0; }
|
2013-10-11 03:42:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {string} key - The cache ID.
|
|
|
|
*/
|
|
|
|
this.key = key;
|
|
|
|
|
2013-10-11 05:30:28 +00:00
|
|
|
this.image = image;
|
|
|
|
|
|
|
|
this.tileWidth = tileWidth;
|
2013-10-11 03:42:11 +00:00
|
|
|
this.tileHeight = tileHeight;
|
2013-10-16 20:25:51 +00:00
|
|
|
this.margin = tileMargin;
|
|
|
|
this.spacing = tileSpacing;
|
2013-10-11 03:42:11 +00:00
|
|
|
|
2013-10-11 05:30:28 +00:00
|
|
|
this.tiles = [];
|
2013-10-11 03:42:11 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Phaser.Tileset.prototype = {
|
|
|
|
|
|
|
|
addTile: function (tile) {
|
|
|
|
|
2013-10-11 05:30:28 +00:00
|
|
|
this.tiles.push(tile);
|
2013-10-11 03:42:11 +00:00
|
|
|
|
|
|
|
return tile;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
getTile: function (index) {
|
|
|
|
|
2013-10-11 05:30:28 +00:00
|
|
|
if (this.tiles[index])
|
2013-10-11 03:42:11 +00:00
|
|
|
{
|
2013-10-11 05:30:28 +00:00
|
|
|
return this.tiles[index];
|
2013-10-11 03:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
2013-10-11 05:30:28 +00:00
|
|
|
},
|
|
|
|
|
2013-10-16 20:25:51 +00:00
|
|
|
setSpacing: function (margin, spacing) {
|
|
|
|
|
|
|
|
this.tileMargin = margin;
|
|
|
|
this.tileSpacing = spacing;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-15 03:28:16 +00:00
|
|
|
canCollide: function (index) {
|
|
|
|
|
|
|
|
if (this.tiles[index])
|
|
|
|
{
|
|
|
|
return this.tiles[index].collideNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
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-10-15 03:28:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setCollisionRange: function (start, stop, left, right, up, down) {
|
|
|
|
|
|
|
|
if (this.tiles[start] && this.tiles[stop] && start < stop)
|
|
|
|
{
|
|
|
|
for (var i = start; i <= stop; i++)
|
|
|
|
{
|
|
|
|
this.tiles[i].setCollision(left, right, up, down);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
setCollision: function (index, left, right, up, down) {
|
|
|
|
|
|
|
|
if (this.tiles[index])
|
|
|
|
{
|
|
|
|
this.tiles[index].setCollision(left, right, up, down);
|
|
|
|
}
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
}
|
2013-10-11 03:42:11 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Phaser.Tileset#total
|
|
|
|
* @property {number} total - The total number of tiles in this Tileset.
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.Tileset.prototype, "total", {
|
|
|
|
|
|
|
|
get: function () {
|
2013-10-11 05:30:28 +00:00
|
|
|
return this.tiles.length;
|
2013-10-11 03:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|