mirror of
https://github.com/wassname/phaser.git
synced 2026-07-26 13:27:43 +08:00
The entire Phaser library has been updated to match the new JSHint configuration.
This commit is contained in:
+1
-2
@@ -5,7 +5,6 @@
|
||||
* @module Phaser.Tile
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Create a new <code>Tile</code>.
|
||||
*
|
||||
@@ -205,7 +204,7 @@ Object.defineProperty(Phaser.Tile.prototype, "right", {
|
||||
* However it does affect the width property.
|
||||
* @method right
|
||||
* @return {number}
|
||||
*/
|
||||
*/
|
||||
get: function () {
|
||||
return this.x + this.width;
|
||||
}
|
||||
|
||||
+33
-33
@@ -1,25 +1,25 @@
|
||||
Phaser.Tilemap = function (game, key) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - Description.
|
||||
*/
|
||||
/**
|
||||
* @property {Phaser.Game} game - Description.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {array} layers - Description.
|
||||
*/
|
||||
this.layers;
|
||||
this.layers = null;
|
||||
|
||||
if (typeof key === 'string')
|
||||
{
|
||||
this.key = key;
|
||||
this.key = key;
|
||||
|
||||
this.layers = game.cache.getTilemapData(key).layers;
|
||||
this.layers = game.cache.getTilemapData(key).layers;
|
||||
this.calculateIndexes();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.layers = [];
|
||||
this.layers = [];
|
||||
}
|
||||
|
||||
this.currentLayer = 0;
|
||||
@@ -55,15 +55,15 @@ Phaser.Tilemap.prototype = {
|
||||
|
||||
this.currentLayer = this.layers.push({
|
||||
|
||||
name: name,
|
||||
width: width,
|
||||
height: height,
|
||||
alpha: 1,
|
||||
visible: true,
|
||||
tileMargin: 0,
|
||||
tileSpacing: 0,
|
||||
format: Phaser.Tilemap.CSV,
|
||||
data: data,
|
||||
name: name,
|
||||
width: width,
|
||||
height: height,
|
||||
alpha: 1,
|
||||
visible: true,
|
||||
tileMargin: 0,
|
||||
tileSpacing: 0,
|
||||
format: Phaser.Tilemap.CSV,
|
||||
data: data,
|
||||
indexes: []
|
||||
|
||||
});
|
||||
@@ -96,10 +96,10 @@ Phaser.Tilemap.prototype = {
|
||||
|
||||
setLayer: function (layer) {
|
||||
|
||||
if (this.layers[layer])
|
||||
{
|
||||
this.currentLayer = layer;
|
||||
}
|
||||
if (this.layers[layer])
|
||||
{
|
||||
this.currentLayer = layer;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
@@ -114,10 +114,10 @@ Phaser.Tilemap.prototype = {
|
||||
|
||||
if (typeof layer === "undefined") { layer = this.currentLayer; }
|
||||
|
||||
if (x >= 0 && x < this.layers[layer].width && y >= 0 && y < this.layers[layer].height)
|
||||
{
|
||||
this.layers[layer].data[y][x] = index;
|
||||
}
|
||||
if (x >= 0 && x < this.layers[layer].width && y >= 0 && y < this.layers[layer].height)
|
||||
{
|
||||
this.layers[layer].data[y][x] = index;
|
||||
}
|
||||
|
||||
this.dirty = true;
|
||||
|
||||
@@ -273,7 +273,7 @@ Phaser.Tilemap.prototype = {
|
||||
|
||||
},
|
||||
|
||||
swapHandler: function (value, index, array) {
|
||||
swapHandler: function (value, index) {
|
||||
|
||||
if (value.index === this._tempA)
|
||||
{
|
||||
@@ -462,14 +462,14 @@ Phaser.Tilemap.prototype = {
|
||||
|
||||
if (this.layers[this.currentLayer].data[y][x] > 1)
|
||||
{
|
||||
if (this.debugMap[this.layers[this.currentLayer].data[y][x]])
|
||||
{
|
||||
args.push("background: " + this.debugMap[this.layers[this.currentLayer].data[y][x]]);
|
||||
}
|
||||
else
|
||||
{
|
||||
args.push("background: #ffffff");
|
||||
}
|
||||
if (this.debugMap[this.layers[this.currentLayer].data[y][x]])
|
||||
{
|
||||
args.push("background: " + this.debugMap[this.layers[this.currentLayer].data[y][x]]);
|
||||
}
|
||||
else
|
||||
{
|
||||
args.push("background: #ffffff");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+47
-47
@@ -1,33 +1,33 @@
|
||||
// Maybe should extend Sprite?
|
||||
Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, tilemap, layer) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - Description.
|
||||
*/
|
||||
/**
|
||||
* @property {Phaser.Game} game - Description.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Description} canvas - Description.
|
||||
* @default
|
||||
*/
|
||||
/**
|
||||
* @property {Description} canvas - Description.
|
||||
* @default
|
||||
*/
|
||||
this.canvas = Phaser.Canvas.create(renderWidth, renderHeight);
|
||||
|
||||
/**
|
||||
* @property {Description} context - Description.
|
||||
* @default
|
||||
*/
|
||||
/**
|
||||
* @property {Description} context - Description.
|
||||
* @default
|
||||
*/
|
||||
this.context = this.canvas.getContext('2d');
|
||||
|
||||
/**
|
||||
* @property {Description} baseTexture - Description.
|
||||
* @default
|
||||
*/
|
||||
/**
|
||||
* @property {Description} baseTexture - Description.
|
||||
* @default
|
||||
*/
|
||||
this.baseTexture = new PIXI.BaseTexture(this.canvas);
|
||||
|
||||
/**
|
||||
* @property {Description} texture - Description.
|
||||
* @default
|
||||
*/
|
||||
/**
|
||||
* @property {Description} texture - Description.
|
||||
* @default
|
||||
*/
|
||||
this.texture = new PIXI.Texture(this.baseTexture);
|
||||
|
||||
this.textureFrame = new Phaser.Frame(0, 0, 0, renderWidth, renderHeight, 'tilemaplayer', game.rnd.uuid());
|
||||
@@ -145,18 +145,18 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset,
|
||||
|
||||
/**
|
||||
* @property {number} scrollFactorX - speed at which this layer scrolls
|
||||
* horizontally, relative to the camera (e.g. scrollFactorX of 0.5 scrolls
|
||||
* half as quickly as the 'normal' camera-locked layers do)
|
||||
* @default 1
|
||||
* horizontally, relative to the camera (e.g. scrollFactorX of 0.5 scrolls
|
||||
* half as quickly as the 'normal' camera-locked layers do)
|
||||
* @default 1
|
||||
*/
|
||||
this.scrollFactorX = 1;
|
||||
this.scrollFactorX = 1;
|
||||
/**
|
||||
* @property {number} scrollFactorY - speed at which this layer scrolls
|
||||
* vertically, relative to the camera (e.g. scrollFactorY of 0.5 scrolls
|
||||
* half as quickly as the 'normal' camera-locked layers do)
|
||||
* @default 1
|
||||
* vertically, relative to the camera (e.g. scrollFactorY of 0.5 scrolls
|
||||
* half as quickly as the 'normal' camera-locked layers do)
|
||||
* @default 1
|
||||
*/
|
||||
this.scrollFactorY = 1;
|
||||
this.scrollFactorY = 1;
|
||||
|
||||
this.tilemap = null;
|
||||
this.layer = null;
|
||||
@@ -251,14 +251,14 @@ Phaser.TilemapLayer.prototype.updateMapData = function (tilemap, layer) {
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype._fixX = function(x) {
|
||||
|
||||
if (this.scrollFactorX === 1)
|
||||
if (this.scrollFactorX === 1)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
var left_edge = x - (this._x / this.scrollFactorX);
|
||||
var leftEdge = x - (this._x / this.scrollFactorX);
|
||||
|
||||
return this._x + left_edge;
|
||||
return this._x + leftEdge;
|
||||
|
||||
}
|
||||
|
||||
@@ -270,14 +270,14 @@ Phaser.TilemapLayer.prototype._fixX = function(x) {
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype._unfixX = function(x) {
|
||||
|
||||
if (this.scrollFactorX === 1)
|
||||
if (this.scrollFactorX === 1)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
var left_edge = x - this._x;
|
||||
var leftEdge = x - this._x;
|
||||
|
||||
return (this._x / this.scrollFactorX) + left_edge;
|
||||
return (this._x / this.scrollFactorX) + leftEdge;
|
||||
|
||||
}
|
||||
|
||||
@@ -289,14 +289,14 @@ Phaser.TilemapLayer.prototype._unfixX = function(x) {
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype._fixY = function(y) {
|
||||
|
||||
if (this.scrollFactorY === 1)
|
||||
if (this.scrollFactorY === 1)
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
var top_edge = y - (this._y / this.scrollFactorY);
|
||||
var topEdge = y - (this._y / this.scrollFactorY);
|
||||
|
||||
return this._y + top_edge;
|
||||
return this._y + topEdge;
|
||||
|
||||
}
|
||||
|
||||
@@ -308,14 +308,14 @@ Phaser.TilemapLayer.prototype._fixY = function(y) {
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype._unfixY = function(y) {
|
||||
|
||||
if (this.scrollFactorY === 1)
|
||||
if (this.scrollFactorY === 1)
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
var top_edge = y - this._y;
|
||||
var topEdge = y - this._y;
|
||||
|
||||
return (this._y / this.scrollFactorY) + top_edge;
|
||||
return (this._y / this.scrollFactorY) + topEdge;
|
||||
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ Phaser.TilemapLayer.prototype.getTileX = function (x) {
|
||||
|
||||
var tileWidth = this.tileWidth * this.scale.x;
|
||||
|
||||
return this.game.math.snapToFloor(this._fixX(x), tileWidth) / tileWidth;
|
||||
return this.game.math.snapToFloor(this._fixX(x), tileWidth) / tileWidth;
|
||||
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ Phaser.TilemapLayer.prototype.getTileY = function (y) {
|
||||
|
||||
var tileHeight = this.tileHeight * this.scale.y;
|
||||
|
||||
return this.game.math.snapToFloor(this._fixY(y), tileHeight) / tileHeight;
|
||||
return this.game.math.snapToFloor(this._fixY(y), tileHeight) / tileHeight;
|
||||
|
||||
}
|
||||
|
||||
@@ -384,9 +384,9 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides
|
||||
y = 0;
|
||||
}
|
||||
|
||||
// adjust the x,y coordinates for scrollFactor
|
||||
x = this._fixX( x );
|
||||
y = this._fixY( y );
|
||||
// adjust the x,y coordinates for scrollFactor
|
||||
x = this._fixX( x );
|
||||
y = this._fixY( y );
|
||||
|
||||
if (width > this.widthInPixels)
|
||||
{
|
||||
@@ -435,9 +435,9 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides
|
||||
|
||||
if (collides === false || (collides && _tile.collideNone === false))
|
||||
{
|
||||
// convert tile coordinates back to camera space for return
|
||||
var _wx = this._unfixX( wx*sx ) / tileWidth;
|
||||
var _wy = this._unfixY( wy*sy ) / tileHeight;
|
||||
// convert tile coordinates back to camera space for return
|
||||
var _wx = this._unfixX( wx*sx ) / tileWidth;
|
||||
var _wy = this._unfixY( wy*sy ) / tileHeight;
|
||||
this._results.push({ x: _wx * sx, right: (_wx * sx) + sx, y: _wy * sy, bottom: (_wy * sy) + sy, width: sx, height: sy, tx: _wx, ty: _wy, tile: _tile });
|
||||
}
|
||||
}
|
||||
|
||||
+134
-134
@@ -1,183 +1,183 @@
|
||||
Phaser.TilemapParser = {
|
||||
|
||||
tileset: function (game, key, tileWidth, tileHeight, tileMax, tileMargin, tileSpacing) {
|
||||
tileset: function (game, key, tileWidth, tileHeight, tileMax, tileMargin, tileSpacing) {
|
||||
|
||||
// How big is our image?
|
||||
var img = game.cache.getTilesetImage(key);
|
||||
// How big is our image?
|
||||
var img = game.cache.getTilesetImage(key);
|
||||
|
||||
if (img == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (img == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var width = img.width;
|
||||
var height = img.height;
|
||||
var width = img.width;
|
||||
var height = img.height;
|
||||
|
||||
// If no tile width/height is given, try and figure it out (won't work if the tileset has margin/spacing)
|
||||
if (tileWidth <= 0)
|
||||
{
|
||||
tileWidth = Math.floor(-width / Math.min(-1, tileWidth));
|
||||
}
|
||||
// If no tile width/height is given, try and figure it out (won't work if the tileset has margin/spacing)
|
||||
if (tileWidth <= 0)
|
||||
{
|
||||
tileWidth = Math.floor(-width / Math.min(-1, tileWidth));
|
||||
}
|
||||
|
||||
if (tileHeight <= 0)
|
||||
{
|
||||
tileHeight = Math.floor(-height / Math.min(-1, tileHeight));
|
||||
}
|
||||
if (tileHeight <= 0)
|
||||
{
|
||||
tileHeight = Math.floor(-height / Math.min(-1, tileHeight));
|
||||
}
|
||||
|
||||
var row = Math.round(width / tileWidth);
|
||||
var column = Math.round(height / tileHeight);
|
||||
var total = row * column;
|
||||
|
||||
if (tileMax !== -1)
|
||||
{
|
||||
total = tileMax;
|
||||
}
|
||||
var row = Math.round(width / tileWidth);
|
||||
var column = Math.round(height / tileHeight);
|
||||
var total = row * column;
|
||||
|
||||
if (tileMax !== -1)
|
||||
{
|
||||
total = tileMax;
|
||||
}
|
||||
|
||||
// Zero or smaller than tile sizes?
|
||||
if (width === 0 || height === 0 || width < tileWidth || height < tileHeight || total === 0)
|
||||
{
|
||||
console.warn("Phaser.TilemapParser.tileSet: width/height zero or width/height < given tileWidth/tileHeight");
|
||||
return null;
|
||||
}
|
||||
// Zero or smaller than tile sizes?
|
||||
if (width === 0 || height === 0 || width < tileWidth || height < tileHeight || total === 0)
|
||||
{
|
||||
console.warn("Phaser.TilemapParser.tileSet: width/height zero or width/height < given tileWidth/tileHeight");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Let's create some tiles
|
||||
var x = tileMargin;
|
||||
var y = tileMargin;
|
||||
// Let's create some tiles
|
||||
var x = tileMargin;
|
||||
var y = tileMargin;
|
||||
|
||||
var tileset = new Phaser.Tileset(img, key, tileWidth, tileHeight, tileMargin, tileSpacing);
|
||||
var tileset = new Phaser.Tileset(img, key, tileWidth, tileHeight, tileMargin, tileSpacing);
|
||||
|
||||
for (var i = 0; i < total; i++)
|
||||
{
|
||||
tileset.addTile(new Phaser.Tile(tileset, i, x, y, tileWidth, tileHeight));
|
||||
for (var i = 0; i < total; i++)
|
||||
{
|
||||
tileset.addTile(new Phaser.Tile(tileset, i, x, y, tileWidth, tileHeight));
|
||||
|
||||
x += tileWidth + tileSpacing;
|
||||
x += tileWidth + tileSpacing;
|
||||
|
||||
if (x === width)
|
||||
{
|
||||
x = tileMargin;
|
||||
y += tileHeight + tileSpacing;
|
||||
}
|
||||
}
|
||||
if (x === width)
|
||||
{
|
||||
x = tileMargin;
|
||||
y += tileHeight + tileSpacing;
|
||||
}
|
||||
}
|
||||
|
||||
return tileset;
|
||||
return tileset;
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
parse: function (game, data, format) {
|
||||
parse: function (game, data, format) {
|
||||
|
||||
if (format === Phaser.Tilemap.CSV)
|
||||
{
|
||||
return this.parseCSV(data);
|
||||
}
|
||||
else if (format === Phaser.Tilemap.TILED_JSON)
|
||||
{
|
||||
return this.parseTiledJSON(data);
|
||||
}
|
||||
if (format === Phaser.Tilemap.CSV)
|
||||
{
|
||||
return this.parseCSV(data);
|
||||
}
|
||||
else if (format === Phaser.Tilemap.TILED_JSON)
|
||||
{
|
||||
return this.parseTiledJSON(data);
|
||||
}
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse csv map data and generate tiles.
|
||||
*
|
||||
* @method Phaser.Tilemap.prototype.parseCSV
|
||||
* @param {string} data - CSV map data.
|
||||
*/
|
||||
parseCSV: function (data) {
|
||||
/**
|
||||
* Parse csv map data and generate tiles.
|
||||
*
|
||||
* @method Phaser.Tilemap.prototype.parseCSV
|
||||
* @param {string} data - CSV map data.
|
||||
*/
|
||||
parseCSV: function (data) {
|
||||
|
||||
// Trim any rogue whitespace from the data
|
||||
data = data.trim();
|
||||
// Trim any rogue whitespace from the data
|
||||
data = data.trim();
|
||||
|
||||
var output = [];
|
||||
var rows = data.split("\n");
|
||||
var height = rows.length;
|
||||
var width = 0;
|
||||
var output = [];
|
||||
var rows = data.split("\n");
|
||||
var height = rows.length;
|
||||
var width = 0;
|
||||
|
||||
for (var i = 0; i < rows.length; i++)
|
||||
{
|
||||
output[i] = [];
|
||||
for (var i = 0; i < rows.length; i++)
|
||||
{
|
||||
output[i] = [];
|
||||
|
||||
var column = rows[i].split(",");
|
||||
var column = rows[i].split(",");
|
||||
|
||||
for (var c = 0; c < column.length; c++)
|
||||
{
|
||||
output[i][c] = parseInt(column[c]);
|
||||
}
|
||||
for (var c = 0; c < column.length; c++)
|
||||
{
|
||||
output[i][c] = parseInt(column[c], 10);
|
||||
}
|
||||
|
||||
if (width === 0)
|
||||
{
|
||||
width = column.length;
|
||||
width = column.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [{ name: 'csv', width: width, height: height, alpha: 1, visible: true, indexes: [], tileMargin: 0, tileSpacing: 0, data: output }];
|
||||
return [{ name: 'csv', width: width, height: height, alpha: 1, visible: true, indexes: [], tileMargin: 0, tileSpacing: 0, data: output }];
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse JSON map data and generate tiles.
|
||||
*
|
||||
* @method Phaser.Tilemap.prototype.parseTiledJSON
|
||||
* @param {string} data - JSON map data.
|
||||
* @param {string} key - Asset key for tileset image.
|
||||
*/
|
||||
parseTiledJSON: function (json) {
|
||||
/**
|
||||
* Parse JSON map data and generate tiles.
|
||||
*
|
||||
* @method Phaser.Tilemap.prototype.parseTiledJSON
|
||||
* @param {string} data - JSON map data.
|
||||
* @param {string} key - Asset key for tileset image.
|
||||
*/
|
||||
parseTiledJSON: function (json) {
|
||||
|
||||
var layers = [];
|
||||
var layers = [];
|
||||
|
||||
for (var i = 0; i < json.layers.length; i++)
|
||||
{
|
||||
// Check it's a data layer
|
||||
if (!json.layers[i].data)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (var i = 0; i < json.layers.length; i++)
|
||||
{
|
||||
// Check it's a data layer
|
||||
if (!json.layers[i].data)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// json.tilewidth
|
||||
// json.tileheight
|
||||
// json.tilewidth
|
||||
// json.tileheight
|
||||
|
||||
var layer = {
|
||||
var layer = {
|
||||
|
||||
name: json.layers[i].name,
|
||||
width: json.layers[i].width,
|
||||
height: json.layers[i].height,
|
||||
alpha: json.layers[i].opacity,
|
||||
visible: json.layers[i].visible,
|
||||
indexes: [],
|
||||
name: json.layers[i].name,
|
||||
width: json.layers[i].width,
|
||||
height: json.layers[i].height,
|
||||
alpha: json.layers[i].opacity,
|
||||
visible: json.layers[i].visible,
|
||||
indexes: [],
|
||||
|
||||
tileMargin: json.tilesets[0].margin,
|
||||
tileSpacing: json.tilesets[0].spacing,
|
||||
tileMargin: json.tilesets[0].margin,
|
||||
tileSpacing: json.tilesets[0].spacing
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
var output = [];
|
||||
var c = 0;
|
||||
var row;
|
||||
var output = [];
|
||||
var c = 0;
|
||||
var row;
|
||||
|
||||
for (var t = 0; t < json.layers[i].data.length; t++)
|
||||
{
|
||||
if (c === 0)
|
||||
{
|
||||
row = [];
|
||||
}
|
||||
for (var t = 0; t < json.layers[i].data.length; t++)
|
||||
{
|
||||
if (c === 0)
|
||||
{
|
||||
row = [];
|
||||
}
|
||||
|
||||
row.push(json.layers[i].data[t]);
|
||||
c++;
|
||||
row.push(json.layers[i].data[t]);
|
||||
c++;
|
||||
|
||||
if (c == json.layers[i].width)
|
||||
{
|
||||
output.push(row);
|
||||
c = 0;
|
||||
}
|
||||
}
|
||||
if (c == json.layers[i].width)
|
||||
{
|
||||
output.push(row);
|
||||
c = 0;
|
||||
}
|
||||
}
|
||||
|
||||
layer.data = output;
|
||||
|
||||
layers.push(layer);
|
||||
layer.data = output;
|
||||
|
||||
layers.push(layer);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return layers;
|
||||
return layers;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ Phaser.Tileset.prototype = {
|
||||
|
||||
checkTileIndex: function (index) {
|
||||
|
||||
return (this.tiles[index]);
|
||||
return (this.tiles[index]);
|
||||
|
||||
},
|
||||
|
||||
@@ -84,7 +84,7 @@ Phaser.Tileset.prototype = {
|
||||
this.tiles[index].setCollision(left, right, up, down);
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user