2013-09-11 01:57:36 +00:00
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, mapData, tileset) {
|
2013-09-11 01:57:36 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Game} game - Description.
|
|
|
|
*/
|
2013-10-11 03:42:11 +00:00
|
|
|
this.game = game;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Description} canvas - Description.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-10-11 03:42:11 +00:00
|
|
|
this.canvas = Phaser.Canvas.create(renderWidth, renderHeight);
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Description} context - Description.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-10-11 03:42:11 +00:00
|
|
|
this.context = this.canvas.getContext('2d');
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Description} baseTexture - Description.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-10-11 03:42:11 +00:00
|
|
|
this.baseTexture = new PIXI.BaseTexture(this.canvas);
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Description} texture - Description.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-10-11 03:42:11 +00:00
|
|
|
this.texture = new PIXI.Texture(this.baseTexture);
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Description} sprite - Description.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-10-11 03:42:11 +00:00
|
|
|
this.sprite = new PIXI.Sprite(this.texture);
|
2013-09-12 01:18:23 +00:00
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
/**
|
|
|
|
* @property {array} mapData - Description.
|
|
|
|
*/
|
2013-09-11 01:57:36 +00:00
|
|
|
this.mapData = [];
|
2013-10-11 03:42:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Description} tileset - Description.
|
|
|
|
*/
|
|
|
|
this.tileset = tileset;
|
|
|
|
|
|
|
|
this.widthInTiles = 0;
|
|
|
|
this.heightInTiles = 0;
|
|
|
|
|
|
|
|
this.renderWidth = renderWidth;
|
|
|
|
this.renderHeight = renderHeight;
|
2013-09-11 01:57:36 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.TilemapLayer.prototype = {
|
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
create: function (width, height) {
|
2013-09-11 01:57:36 +00:00
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
this.mapData = [];
|
2013-09-11 01:57:36 +00:00
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
var data;
|
|
|
|
|
|
|
|
for (var y = 0; y < height; y++)
|
2013-09-11 01:57:36 +00:00
|
|
|
{
|
2013-10-11 03:42:11 +00:00
|
|
|
this.mapData[y] = [];
|
|
|
|
|
|
|
|
for (var x = 0; x < width; x++)
|
2013-09-11 01:57:36 +00:00
|
|
|
{
|
2013-10-11 03:42:11 +00:00
|
|
|
this.mapData[y][x] = 0;
|
2013-09-11 01:57:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
this.widthInTiles = width;
|
|
|
|
this.heightInTiles = height;
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-09-11 01:57:36 +00:00
|
|
|
* Set a specific tile with its x and y in tiles.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @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.
|
2013-09-11 01:57:36 +00:00
|
|
|
*/
|
|
|
|
putTile: function (x, y, index) {
|
|
|
|
|
|
|
|
if (y >= 0 && y < this.mapData.length)
|
|
|
|
{
|
|
|
|
if (x >= 0 && x < this.mapData[y].length)
|
|
|
|
{
|
|
|
|
this.mapData[y][x] = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
dump: function () {
|
2013-09-11 01:57:36 +00:00
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
var txt = '';
|
|
|
|
var args = [''];
|
2013-09-11 01:57:36 +00:00
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
for (var y = 0; y < this.heightInTiles; y++)
|
2013-09-11 01:57:36 +00:00
|
|
|
{
|
2013-10-11 03:42:11 +00:00
|
|
|
for (var x = 0; x < this.widthInTiles; x++)
|
2013-09-12 14:39:52 +00:00
|
|
|
{
|
2013-10-11 03:42:11 +00:00
|
|
|
txt += "%c ";
|
2013-09-11 01:57:36 +00:00
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
if (this.mapData[y][x] > 0)
|
2013-09-11 01:57:36 +00:00
|
|
|
{
|
2013-10-11 03:42:11 +00:00
|
|
|
args.push("background: rgb(50, 50, 50)");
|
2013-09-11 01:57:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-11 03:42:11 +00:00
|
|
|
args.push("background: rgb(0, 0, 0)");
|
2013-09-11 01:57:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
txt += "\n";
|
2013-09-11 01:57:36 +00:00
|
|
|
}
|
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
args[0] = txt;
|
|
|
|
console.log.apply(console, args);
|
2013-09-11 01:57:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2013-09-12 03:24:01 +00:00
|
|
|
|