Updated Tilemap classes and further tests.

This commit is contained in:
photonstorm
2014-01-14 22:34:41 +00:00
parent ff7cad102c
commit bd66be1804
8 changed files with 418 additions and 85 deletions
@@ -0,0 +1,65 @@
{ "height":18,
"layers":[
{
"data":[26, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 26, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1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 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 26, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 26, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 26, 0, 0, 0, 0, 0, 0, 26, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 0, 26, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 9, 1, 1, 1, 1, 1, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
"height":18,
"name":"Tile Layer 1",
"opacity":1,
"properties":
{
"collides":"true"
},
"type":"tilelayer",
"visible":true,
"width":50,
"x":0,
"y":0
}],
"orientation":"orthogonal",
"properties":
{
},
"tileheight":32,
"tilesets":[
{
"firstgid":1,
"image":"..\/tiles\/ground_1x1.png",
"imageheight":32,
"imagewidth":800,
"margin":0,
"name":"ground_1x1",
"properties":
{
},
"spacing":0,
"tileheight":32,
"tileproperties":
{
"1":
{
"bounce":"1"
}
},
"tilewidth":32
},
{
"firstgid":26,
"image":"..\/..\/sprites\/coin.png",
"imageheight":32,
"imagewidth":192,
"margin":0,
"name":"coin",
"properties":
{
},
"spacing":0,
"tileheight":32,
"tilewidth":32
}],
"tilewidth":32,
"version":1,
"width":50
}
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" width="50" height="18" tilewidth="32" tileheight="32">
<tileset firstgid="1" name="ground_1x1" tilewidth="32" tileheight="32">
<image source="../tiles/ground_1x1.png" width="800" height="32"/>
<tile id="1">
<properties>
<property name="bounce" value="1"/>
</properties>
</tile>
</tileset>
<tileset firstgid="26" name="coin" tilewidth="32" tileheight="32">
<image source="../../sprites/coin.png" width="192" height="32"/>
</tileset>
<layer name="Tile Layer 1" width="50" height="18">
<properties>
<property name="collides" value="true"/>
</properties>
<data encoding="base64">
GgAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAEAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAEAAAAAAAAAAAAAAAAAAAAaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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ABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAA
</data>
</layer>
</map>
+101
View File
@@ -0,0 +1,101 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.tilemap('map', 'assets/tilemaps/maps/tile_collision_test.json', null, Phaser.Tilemap.TILED_JSON);
game.load.image('ground_1x1', 'assets/tilemaps/tiles/ground_1x1.png');
game.load.image('phaser', 'assets/sprites/arrow.png');
game.load.spritesheet('coin', 'assets/sprites/coin.png', 32, 32);
}
var map;
var layer;
var sprite;
var cursors;
function create() {
map = game.add.tilemap('map');
map.addTilesetImage('ground_1x1');
map.addTilesetImage('coin');
map.setCollisionBetween(1, 12);
map.setTileIndexCallback(26, hitCoin, this);
map.setTileLocationCallback(2, 0, 1, 1, hitCoin, this);
layer = map.createLayer('Tile Layer 1');
layer.debug = true;
layer.resizeWorld();
sprite = game.add.sprite(260, 100, 'phaser');
sprite.anchor.setTo(0.5, 0.5);
sprite.body.setSize(16, 16, 8, 8);
// We'll set a lower max angular velocity here to keep it from going totally nuts
sprite.body.maxAngular = 500;
// Apply a drag otherwise the sprite will just spin and never slow down
sprite.body.angularDrag = 50;
sprite.body.bounce.x = 0.8;
sprite.body.bounce.y = 0.8;
game.camera.follow(sprite);
cursors = game.input.keyboard.createCursorKeys();
}
function hitCoin(sprite, tile) {
tile.tile.alpha = 0.2;
layer.dirty = true;
return false;
}
function update() {
game.physics.collide(sprite, layer);
sprite.body.velocity.x = 0;
sprite.body.velocity.y = 0;
sprite.body.angularVelocity = 0;
if (cursors.left.isDown)
{
sprite.body.angularVelocity = -300;
}
else if (cursors.right.isDown)
{
sprite.body.angularVelocity = 300;
}
if (cursors.up.isDown)
{
game.physics.velocityFromAngle(sprite.angle, 300, sprite.body.velocity);
}
}
function render() {
// game.debug.renderSpriteBody(sprite);
game.debug.renderSpriteBounds(sprite);
}
+33
View File
@@ -795,6 +795,22 @@ Phaser.Physics.Arcade.prototype = {
if (Phaser.Rectangle.intersects(body, tile))
{
// They overlap. Any custom callbacks?
if (tile.tile.callback || tile.layer.callbacks[tile.tile.index])
{
// A local callback takes priority over a global callback.
if (tile.tile.callback && tile.tile.callback.call(tile.tile.callbackContext, body.sprite, tile) === false)
{
// Is there a tile specific collision callback? If it returns true then we can carry on, otherwise we should abort.
continue;
}
else if (tile.layer.callbacks[tile.tile.index] && tile.layer.callbacks[tile.tile.index].callback.call(tile.layer.callbacks[tile.tile.index].callbackContext, body.sprite, tile) === false)
{
// Is there a tile index collision callback? If it returns true then we can carry on, otherwise we should abort.
continue;
}
}
if (body.deltaX() < 0 && body.allowCollision.left && tile.tile.faceRight)
{
// LEFT
@@ -921,12 +937,29 @@ Phaser.Physics.Arcade.prototype = {
return false;
}
// They overlap. Any custom callbacks?
if (tile.tile.callback || tile.layer.callbacks[tile.tile.index])
{
// A local callback takes priority over a global callback.
if (tile.tile.callback && tile.tile.callback.call(tile.tile.callbackContext, body.sprite, tile) === false)
{
// Is there a tile specific collision callback? If it returns true then we can carry on, otherwise we should abort.
return false;
}
else if (tile.layer.callbacks[tile.tile.index] && tile.layer.callbacks[tile.tile.index].callback.call(tile.layer.callbacks[tile.tile.index].callbackContext, body.sprite, tile) === false)
{
// Is there a tile index collision callback? If it returns true then we can carry on, otherwise we should abort.
return false;
}
}
// use body var instead
body.overlapX = 0;
body.overlapY = 0;
// Remember - this happens AFTER the body has been moved by the motion update, so it needs moving back again
// console.log('---------------------------------------------------------------------------------------------');
// console.log(tile);
// console.log('tx', tile.x, 'ty', tile.y, 'tw', tile.width, 'th', tile.height, 'tr', tile.right, 'tb', tile.bottom);
// console.log('bx', body.x, 'by', body.y, 'bw', body.width, 'bh', body.height, 'br', body.right, 'bb', body.bottom);
// console.log(Phaser.Rectangle.intersects(body, tile));
+27 -19
View File
@@ -10,13 +10,19 @@
* @class Phaser.Tile
* @classdesc A Tile is a representation of a single tile within the Tilemap.
* @constructor
* @param {object} layer - The layer in the Tilemap data that this tile belongs to.
* @param {number} index - The index of this tile type in the core map data.
* @param {number} x - The x coordinate of this tile.
* @param {number} y - The y coordinate of this tile.
* @param {number} width - Width of the tile.
* @param {number} height - Height of the tile.
*/
Phaser.Tile = function (index, x, y, width, height) {
Phaser.Tile = function (layer, index, x, y, width, height) {
/**
* @property {object} layer - The layer in the Tilemap data that this tile belongs to.
*/
this.layer = layer;
/**
* @property {number} index - The index of this tile within the map data corresponding to the tileset.
@@ -109,38 +115,27 @@ Phaser.Tile = function (index, x, y, width, height) {
this.collideDown = false;
/**
* @property {boolean} separateX - Enable separation at x-axis.
* @property {function} callback - Tile collision callback.
* @default
*/
// this.separateX = true;
this.callback = null;
/**
* @property {boolean} separateY - Enable separation at y-axis.
* @property {object} callbackContext - The context in which the collision callback will be called.
* @default
*/
// this.separateY = true;
/**
* @property {boolean} collisionCallback - Tilemap collision callback.
* @default
*/
this.collisionCallback = null;
/**
* @property {boolean} collisionCallback - Tilemap collision callback context.
* @default
*/
this.collisionCallbackContext = this;
this.callbackContext = this;
};
Phaser.Tile.prototype = {
/**
* Set callback to be called when this tilemap collides.
* Set a callback to be called when this tile is hit by an object.
* The callback must true true for collision processing to take place.
*
* @method Phaser.Tile#setCollisionCallback
* @param {Function} callback - Callback function.
* @param {function} callback - Callback function.
* @param {object} context - Callback will be called with this context.
*/
setCollisionCallback: function (callback, context) {
@@ -227,6 +222,19 @@ Phaser.Tile.prototype = {
Phaser.Tile.prototype.constructor = Phaser.Tile;
/**
* @name Phaser.Tile#canCollide
* @property {boolean} canCollide - True if this tile can collide or has a collision callback.
* @readonly
*/
Object.defineProperty(Phaser.Tile.prototype, "canCollide", {
get: function () {
return (this.collides || this.collisionCallback || this.layer.callbacks[this.index]);
}
});
/**
* @name Phaser.Tile#bottom
* @property {number} bottom - The sum of the y and height properties.
+137 -54
View File
@@ -357,9 +357,66 @@ Phaser.Tilemap.prototype = {
},
setTileCallback: function (indexes, layer, callback, callbackContext) {
/**
* Sets a global collision callback for the given tile index within the layer. This will affect all tiles on this layer that have the same index.
* If a callback is already set for the tile index it will be replaced. Set the callback to null to remove it.
* If you want to set a callback for a tile at a specific location on the map then see setTileLocationCallback.
*
* @method Phaser.Tileset#setTileIndexCallback
* @param {number|array} indexes - Either a single tile index, or an array of tile indexes to have a collision callback set for.
* @param {function} callback - The callback that will be invoked when the tile is collided with.
* @param {object} callbackContext - The context under which the callback is called.
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to operate on. If not given will default to this.currentLayer.
*/
setTileIndexCallback: function (indexes, callback, callbackContext, layer) {
layer = this.getLayer(layer);
if (typeof indexes === 'number')
{
// This may seem a bit wasteful, because it will cause empty array elements to be created, but the look-up cost is much
// less than having to iterate through the callbacks array hunting down tile indexes each time, so I'll take the small memory hit.
this.layers[layer].callbacks[indexes] = { callback: callback, callbackContext: callbackContext };
}
else
{
for (var i = 0, len = indexes.length; i < len; i++)
{
this.layers[layer].callbacks[indexes[i]] = { callback: callback, callbackContext: callbackContext };
}
}
},
/**
* Sets a global collision callback for the given tile index within the layer. This will affect all tiles on this layer that have the same index.
* If a callback is already set for the tile index it will be replaced. Set the callback to null to remove it.
* If you want to set a callback for a tile at a specific location on the map then see setTileLocationCallback.
*
* @method Phaser.Tileset#setTileLocationCallback
* @param {number} x - X position of the top left of the area to copy (given in tiles, not pixels)
* @param {number} y - Y position of the top left of the area to copy (given in tiles, not pixels)
* @param {number} width - The width of the area to copy (given in tiles, not pixels)
* @param {number} height - The height of the area to copy (given in tiles, not pixels)
* @param {function} callback - The callback that will be invoked when the tile is collided with.
* @param {object} callbackContext - The context under which the callback is called.
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to operate on. If not given will default to this.currentLayer.
*/
setTileLocationCallback: function (x, y, width, height, callback, callbackContext, layer) {
layer = this.getLayer(layer);
this.copy(x, y, width, height, layer);
if (this._results.length < 2)
{
return;
}
for (var i = 1; i < this._results.length; i++)
{
this._results[i].setCollisionCallback(callback, callbackContext);
}
},
@@ -465,16 +522,15 @@ Phaser.Tilemap.prototype = {
* @protected
* @param {number} index - The index of the tile on the layer.
* @param {boolean} [collides=true] - If true it will enable collision on the tile. If false it will clear collision values from the tile.
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to operate on. If not given will default to this.currentLayer.
* @param {number} [layer] - The layer to operate on. If not given will default to this.currentLayer.
* @param {boolean} [recalculate=true] - Recalculates the tile faces after the update.
*/
setCollisionByIndex: function (index, collides, layer, recalculate) {
if (typeof collides === 'undefined') { collides = true; }
if (typeof layer === 'undefined') { layer = this.currentLayer; }
if (typeof recalculate === 'undefined') { recalculate = true; }
layer = this.getLayer(layer);
for (var y = 0; y < this.layers[layer].height ; y++)
{
for (var x = 0; x < this.layers[layer].width; x++)
@@ -516,6 +572,10 @@ Phaser.Tilemap.prototype = {
{
layer = this.currentLayer;
}
// else if (typeof layer === 'number')
// {
// layer = layer;
// }
else if (typeof layer === 'string')
{
layer = this.getLayerIndex(layer);
@@ -543,8 +603,6 @@ Phaser.Tilemap.prototype = {
var left = null;
var right = null;
// console.log(this.layers[layer].width, 'x', this.layers[layer].height);
for (var y = 0, h = this.layers[layer].height; y < h; y++)
{
for (var x = 0, w = this.layers[layer].width; x < w; x++)
@@ -588,12 +646,13 @@ Phaser.Tilemap.prototype = {
},
/**
* Internal function.
* Gets the tile above the tile coordinates given.
* Mostly used as an internal function by calculateFaces.
*
* @method Phaser.Tileset#getTileAbove
* @param {number} layer - The layer to operate on.
* @param {number} x - X.
* @param {number} y - Y.
* @param {number} layer - The local layer index to get the tile from. Can be determined by Tilemap.getLayer().
* @param {number} x - The x coordinate to get the tile from. In tiles, not pixels.
* @param {number} y - The y coordinate to get the tile from. In tiles, not pixels.
*/
getTileAbove: function (layer, x, y) {
@@ -607,12 +666,13 @@ Phaser.Tilemap.prototype = {
},
/**
* Internal function.
* Gets the tile below the tile coordinates given.
* Mostly used as an internal function by calculateFaces.
*
* @method Phaser.Tileset#getTileBelow
* @param {number} layer - The layer to operate on.
* @param {number} x - X.
* @param {number} y - Y.
* @param {number} layer - The local layer index to get the tile from. Can be determined by Tilemap.getLayer().
* @param {number} x - The x coordinate to get the tile from. In tiles, not pixels.
* @param {number} y - The y coordinate to get the tile from. In tiles, not pixels.
*/
getTileBelow: function (layer, x, y) {
@@ -626,12 +686,13 @@ Phaser.Tilemap.prototype = {
},
/**
* Internal function.
* Gets the tile to the left of the tile coordinates given.
* Mostly used as an internal function by calculateFaces.
*
* @method Phaser.Tileset#getTileLeft
* @param {number} layer - The layer to operate on.
* @param {number} x - X.
* @param {number} y - Y.
* @param {number} layer - The local layer index to get the tile from. Can be determined by Tilemap.getLayer().
* @param {number} x - The x coordinate to get the tile from. In tiles, not pixels.
* @param {number} y - The y coordinate to get the tile from. In tiles, not pixels.
*/
getTileLeft: function (layer, x, y) {
@@ -645,12 +706,13 @@ Phaser.Tilemap.prototype = {
},
/**
* Internal function.
* Gets the tile to the right of the tile coordinates given.
* Mostly used as an internal function by calculateFaces.
*
* @method Phaser.Tileset#getTileRight
* @param {number} layer - The layer to operate on.
* @param {number} x - X.
* @param {number} y - Y.
* @param {number} layer - The local layer index to get the tile from. Can be determined by Tilemap.getLayer().
* @param {number} x - The x coordinate to get the tile from. In tiles, not pixels.
* @param {number} y - The y coordinate to get the tile from. In tiles, not pixels.
*/
getTileRight: function (layer, x, y) {
@@ -667,10 +729,12 @@ Phaser.Tilemap.prototype = {
* Sets the current layer to the given index.
*
* @method Phaser.Tilemap#setLayer
* @param {number} layer - Sets the current layer to the given index.
* @param {number|string|Phaser.TilemapLayer} layer - The layer to set as current.
*/
setLayer: function (layer) {
layer = this.getLayer(layer);
if (this.layers[layer])
{
this.currentLayer = layer;
@@ -680,15 +744,16 @@ Phaser.Tilemap.prototype = {
/**
* Puts a tile of the given index value at the coordinate specified.
*
* @method Phaser.Tilemap#putTile
* @param {Phaser.Tile|number} tile - The index of this tile to set or a Phaser.Tile object.
* @param {number} x - X position to place the tile (given in tile units, not pixels)
* @param {number} y - Y position to place the tile (given in tile units, not pixels)
* @param {number} [layer] - The Tilemap Layer to operate on.
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to modify.
*/
putTile: function (tile, x, y, layer) {
if (typeof layer === "undefined") { layer = this.currentLayer; }
layer = this.getLayer(layer);
if (x >= 0 && x < this.layers[layer].width && y >= 0 && y < this.layers[layer].height)
{
@@ -709,17 +774,18 @@ Phaser.Tilemap.prototype = {
/**
* Puts a tile into the Tilemap layer. The coordinates are given in pixel values.
*
* @method Phaser.Tilemap#putTileWorldXY
* @param {Phaser.Tile|number} tile - The index of this tile to set or a Phaser.Tile object.
* @param {number} x - X position to insert the tile (given in pixels)
* @param {number} y - Y position to insert the tile (given in pixels)
* @param {number} tileWidth - The width of the tile in pixels.
* @param {number} tileHeight - The height of the tile in pixels.
* @param {number} [layer] - The Tilemap Layer to operate on.
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to modify.
*/
putTileWorldXY: function (tile, x, y, tileWidth, tileHeight, layer) {
if (typeof layer === "undefined") { layer = this.currentLayer; }
layer = this.getLayer(layer);
x = this.game.math.snapToFloor(x, tileWidth) / tileWidth;
y = this.game.math.snapToFloor(y, tileHeight) / tileHeight;
@@ -730,15 +796,16 @@ Phaser.Tilemap.prototype = {
/**
* Gets a tile from the Tilemap Layer. The coordinates are given in tile values.
*
* @method Phaser.Tilemap#getTile
* @param {number} x - X position to get the tile from (given in tile units, not pixels)
* @param {number} y - Y position to get the tile from (given in tile units, not pixels)
* @param {number} [layer] - The Tilemap Layer to operate on.
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to get the tile from.
* @return {Phaser.Tile} The tile at the given coordinates.
*/
getTile: function (x, y, layer) {
if (typeof layer === "undefined") { layer = this.currentLayer; }
layer = this.getLayer(layer);
if (x >= 0 && x < this.layers[layer].width && y >= 0 && y < this.layers[layer].height)
{
@@ -749,15 +816,16 @@ Phaser.Tilemap.prototype = {
/**
* Gets a tile from the Tilemap layer. The coordinates are given in pixel values.
*
* @method Phaser.Tilemap#getTileWorldXY
* @param {number} x - X position to get the tile from (given in pixels)
* @param {number} y - Y position to get the tile from (given in pixels)
* @param {number} [layer] - The Tilemap Layer to operate on.
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to get the tile from.
* @return {Phaser.Tile} The tile at the given coordinates.
*/
getTileWorldXY: function (x, y, tileWidth, tileHeight, layer) {
if (typeof layer === "undefined") { layer = this.currentLayer; }
layer = this.getLayer(layer);
x = this.game.math.snapToFloor(x, tileWidth) / tileWidth;
y = this.game.math.snapToFloor(y, tileHeight) / tileHeight;
@@ -768,17 +836,18 @@ Phaser.Tilemap.prototype = {
/**
* Copies all of the tiles in the given rectangular block into the tilemap data buffer.
*
* @method Phaser.Tilemap#copy
* @param {number} x - X position of the top left of the area to copy (given in tiles, not pixels)
* @param {number} y - Y position of the top left of the area to copy (given in tiles, not pixels)
* @param {number} width - The width of the area to copy (given in tiles, not pixels)
* @param {number} height - The height of the area to copy (given in tiles, not pixels)
* @param {number} [layer] - The Tilemap Layer to operate on.
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to copy the tiles from.
* @return {array} An array of the tiles that were copied.
*/
copy: function (x, y, width, height, layer) {
if (typeof layer === "undefined") { layer = this.currentLayer; }
layer = this.getLayer(layer);
if (!this.layers[layer])
{
@@ -829,17 +898,19 @@ Phaser.Tilemap.prototype = {
/**
* Pastes a previously copied block of tile data into the given x/y coordinates. Data should have been prepared with Tilemap.copy.
*
* @method Phaser.Tilemap#paste
* @param {number} x - X position of the top left of the area to paste to (given in tiles, not pixels)
* @param {number} y - Y position of the top left of the area to paste to (given in tiles, not pixels)
* @param {array} tileblock - The block of tiles to paste.
* @param {number} layer - The Tilemap Layer to operate on.
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to paste the tiles into.
*/
paste: function (x, y, tileblock, layer) {
if (typeof x === "undefined") { x = 0; }
if (typeof y === "undefined") { y = 0; }
if (typeof layer === "undefined") { layer = this.currentLayer; }
layer = this.getLayer(layer);
if (!tileblock || tileblock.length < 2)
{
@@ -861,7 +932,8 @@ Phaser.Tilemap.prototype = {
},
/**
* Swap tiles with 2 kinds of indexes.
* Scans the given area for tiles with an index matching tileA and swaps them with tileB.
*
* @method Phaser.Tilemap#swapTile
* @param {number} tileA - First tile index.
* @param {number} tileB - Second tile index.
@@ -869,10 +941,11 @@ Phaser.Tilemap.prototype = {
* @param {number} y - Y position of the top left of the area to operate one, given in tiles, not pixels.
* @param {number} width - The width in tiles of the area to operate on.
* @param {number} height - The height in tiles of the area to operate on.
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to operate on.
*/
swap: function (tileA, tileB, x, y, width, height, layer) {
if (typeof layer === "undefined") { layer = this.currentLayer; }
layer = this.getLayer(layer);
this.copy(x, y, width, height, layer);
@@ -892,7 +965,9 @@ Phaser.Tilemap.prototype = {
/**
* Internal function that handles the swapping of tiles.
*
* @method Phaser.Tilemap#swapHandler
* @private
* @param {number} value
* @param {number} index
*/
@@ -910,7 +985,8 @@ Phaser.Tilemap.prototype = {
},
/**
* For each tile in the given area (defined by x/y and width/height) run the given callback.
* For each tile in the given area defined by x/y and width/height run the given callback.
*
* @method Phaser.Tilemap#forEach
* @param {number} callback - The callback. Each tile in the given area will be passed to this callback as the first and only parameter.
* @param {number} context - The context under which the callback should be run.
@@ -918,11 +994,11 @@ Phaser.Tilemap.prototype = {
* @param {number} y - Y position of the top left of the area to operate one, given in tiles, not pixels.
* @param {number} width - The width in tiles of the area to operate on.
* @param {number} height - The height in tiles of the area to operate on.
* @param {number} [layer] - The Tilemap Layer to operate on.
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to operate on.
*/
forEach: function (callback, context, x, y, width, height, layer) {
if (typeof layer === "undefined") { layer = this.currentLayer; }
layer = this.getLayer(layer);
this.copy(x, y, width, height, layer);
@@ -938,19 +1014,20 @@ Phaser.Tilemap.prototype = {
},
/**
* Replaces one type of tile with another in the given area (defined by x/y and width/height).
* Scans the given area for tiles with an index matching `source` and updates their index to match `dest`.
*
* @method Phaser.Tilemap#replace
* @param {number} tileA - First tile index.
* @param {number} tileB - Second tile index.
* @param {number} source - The tile index value to scan for.
* @param {number} dest - The tile index value to replace found tiles with.
* @param {number} x - X position of the top left of the area to operate one, given in tiles, not pixels.
* @param {number} y - Y position of the top left of the area to operate one, given in tiles, not pixels.
* @param {number} width - The width in tiles of the area to operate on.
* @param {number} height - The height in tiles of the area to operate on.
* @param {number} [layer] - The Tilemap Layer to operate on.
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to operate on.
*/
replace: function (tileA, tileB, x, y, width, height, layer) {
replace: function (source, dest, x, y, width, height, layer) {
if (typeof layer === "undefined") { layer = this.currentLayer; }
layer = this.getLayer(layer);
this.copy(x, y, width, height, layer);
@@ -961,9 +1038,9 @@ Phaser.Tilemap.prototype = {
for (var i = 1; i < this._results.length; i++)
{
if (this._results[i].index === tileA)
if (this._results[i].index === source)
{
this._results[i].index = tileB;
this._results[i].index = dest;
}
}
@@ -973,16 +1050,17 @@ Phaser.Tilemap.prototype = {
/**
* Randomises a set of tiles in a given area.
*
* @method Phaser.Tilemap#random
* @param {number} x - X position of the top left of the area to operate one, given in tiles, not pixels.
* @param {number} y - Y position of the top left of the area to operate one, given in tiles, not pixels.
* @param {number} width - The width in tiles of the area to operate on.
* @param {number} height - The height in tiles of the area to operate on.
* @param {number} [layer] - The Tilemap Layer to operate on.
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to operate on.
*/
random: function (x, y, width, height, layer) {
if (typeof layer === "undefined") { layer = this.currentLayer; }
layer = this.getLayer(layer);
this.copy(x, y, width, height, layer);
@@ -1017,16 +1095,17 @@ Phaser.Tilemap.prototype = {
/**
* Shuffles a set of tiles in a given area. It will only randomise the tiles in that area, so if they're all the same nothing will appear to have changed!
*
* @method Phaser.Tilemap#shuffle
* @param {number} x - X position of the top left of the area to operate one, given in tiles, not pixels.
* @param {number} y - Y position of the top left of the area to operate one, given in tiles, not pixels.
* @param {number} width - The width in tiles of the area to operate on.
* @param {number} height - The height in tiles of the area to operate on.
* @param {number} [layer] - The Tilemap Layer to operate on.
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to operate on.
*/
shuffle: function (x, y, width, height, layer) {
if (typeof layer === "undefined") { layer = this.currentLayer; }
layer = this.getLayer(layer);
this.copy(x, y, width, height, layer);
@@ -1058,17 +1137,18 @@ Phaser.Tilemap.prototype = {
/**
* Fills the given area with the specified tile.
*
* @method Phaser.Tilemap#fill
* @param {number} index - The index of the tile that the area will be filled with.
* @param {number} x - X position of the top left of the area to operate one, given in tiles, not pixels.
* @param {number} y - Y position of the top left of the area to operate one, given in tiles, not pixels.
* @param {number} width - The width in tiles of the area to operate on.
* @param {number} height - The height in tiles of the area to operate on.
* @param {number} [layer] - The Tilemap Layer to operate on.
* @param {number|string|Phaser.TilemapLayer} [layer] - The layer to operate on.
*/
fill: function (index, x, y, width, height, layer) {
if (typeof layer === "undefined") { layer = this.currentLayer; }
layer = this.getLayer(layer);
this.copy(x, y, width, height, layer);
@@ -1088,6 +1168,7 @@ Phaser.Tilemap.prototype = {
/**
* Removes all layers from this tile map.
*
* @method Phaser.Tilemap#removeAllLayers
*/
removeAllLayers: function () {
@@ -1099,6 +1180,7 @@ Phaser.Tilemap.prototype = {
/**
* Dumps the tilemap data out to the console.
*
* @method Phaser.Tilemap#dump
*/
dump: function () {
@@ -1139,6 +1221,7 @@ Phaser.Tilemap.prototype = {
/**
* Removes all layers from this tile map and nulls the game reference.
*
* @method Phaser.Tilemap#destroy
*/
destroy: function () {
+29 -9
View File
@@ -94,7 +94,7 @@ Phaser.TilemapLayer = function (game, tilemap, index, width, height) {
this.tileColor = 'rgb(255, 255, 255)';
/**
* @property {boolean} debug - If set to true the collideable tile edges path will be rendered.
* @property {boolean} debug - If set to true the collideable tile edges path will be rendered. Only works when game is running in Phaser.CANVAS mode.
* @default
*/
this.debug = false;
@@ -123,6 +123,12 @@ Phaser.TilemapLayer = function (game, tilemap, index, width, height) {
*/
this.debugFillColor = 'rgba(0, 255, 0, 0.2)';
/**
* @property {string} debugCallbackColor - If debug is true this is the color used to outline the edges of tiles that have collision callbacks. Provide in hex or rgb/rgba string format.
* @default
*/
this.debugCallbackColor = 'rgba(255, 0, 0, 1)';
/**
* @property {number} scrollFactorX - speed at which this layer scrolls
* horizontally, relative to the camera (e.g. scrollFactorX of 0.5 scrolls
@@ -485,7 +491,7 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides
// This should apply the layer x/y here
this._results.length = 0;
var _tile = null;
// var _tile = null;
for (var wy = this._ty; wy < this._ty + this._th; wy++)
{
@@ -493,13 +499,13 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides
{
if (this.layer.data[wy] && this.layer.data[wy][wx])
{
_tile = this.layer.data[wy][wx];
// _tile = this.layer.data[wy][wx];
if (_tile)
{
if (collides === false || (collides && _tile.collides))
// if (_tile && (collides === false || (collides && _tile.collides))
// {
if (collides === false || (collides && this.layer.data[wy][wx].canCollide))
{
// convert tile coordinates back to camera space for return
// Convert tile coordinates back to camera space for return
var _wx = this._unfixX(wx * this._cw) / this._cw;
var _wy = this._unfixY(wy * this._ch) / this._ch;
@@ -508,10 +514,11 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides
y: _wy * this._ch,
right: (_wx * this._cw) + this._cw,
bottom: (_wy * this._ch) + this._ch,
tile: _tile
tile: this.layer.data[wy][wx],
layer: this.layer.data[wy][wx].layer
});
}
}
// }
}
}
}
@@ -746,6 +753,11 @@ Phaser.TilemapLayer.prototype.render = function () {
if (set.image)
{
if (this.debug === false && tile.alpha !== this.context.globalAlpha)
{
this.context.globalAlpha = tile.alpha;
}
if (set.tileWidth !== this.map.tileWidth || set.tileHeight !== this.map.tileHeight)
{
// TODO: Smaller sized tile check
@@ -870,6 +882,14 @@ Phaser.TilemapLayer.prototype.renderDebug = function () {
this.context.stroke();
}
// Collision callback
if (tile && (tile.collisionCallback || tile.layer.callbacks[tile.index]))
{
this.context.fillStyle = this.debugCallbackColor;
this.context.fillRect(this._tx, this._ty, this._cw, this._ch);
this.context.fillStyle = this.debugFillColor;
}
this._tx += this.map.tileWidth;
}
+4 -3
View File
@@ -182,7 +182,8 @@ Phaser.TilemapParser = {
alpha: json.layers[i].opacity,
visible: json.layers[i].visible,
properties: {},
indexes: []
indexes: [],
callbacks: []
};
@@ -198,7 +199,7 @@ Phaser.TilemapParser = {
// Loop through the data field in the JSON.
// This is an array containing the tile indexes, one after the other. 0 = no tile, everything else = the tile index (starting at 1)
// If the map contains multiple tilesets then the indexes are relative to that which the set starts from
// If the map contains multiple tilesets then the indexes are relative to that which the set starts from.
// Need to set which tileset in the cache = which tileset in the JSON, if you do this manually it means you can use the same map data but a new tileset.
for (var t = 0, len = json.layers[i].data.length; t < len; t++)
@@ -206,7 +207,7 @@ Phaser.TilemapParser = {
// index, x, y, width, height
if (json.layers[i].data[t] > 0)
{
row.push(new Phaser.Tile(json.layers[i].data[t], x, output.length, json.tilewidth, json.tileheight));
row.push(new Phaser.Tile(layer, json.layers[i].data[t], x, output.length, json.tilewidth, json.tileheight));
}
else
{