2013-11-27 16:33:49 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2014-02-05 05:54:25 +00:00
|
|
|
* @copyright 2014 Photon Storm Ltd.
|
2013-11-27 16:33:49 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A Tilemap Layer is a set of map data combined with a Tileset in order to render that data to the game.
|
|
|
|
*
|
|
|
|
* @class Phaser.TilemapLayer
|
|
|
|
* @constructor
|
|
|
|
* @param {Phaser.Game} game - Game reference to the currently running game.
|
|
|
|
* @param {Phaser.Tilemap} tilemap - The tilemap to which this layer belongs.
|
2013-12-19 03:49:28 +00:00
|
|
|
* @param {number} index - The layer index within the map that this TilemapLayer represents.
|
|
|
|
* @param {number} width - Width of the renderable area of the layer.
|
|
|
|
* @param {number} height - Height of the renderable area of the layer.
|
2013-11-27 16:33:49 +00:00
|
|
|
*/
|
2013-12-19 03:49:28 +00:00
|
|
|
Phaser.TilemapLayer = function (game, tilemap, index, width, height) {
|
2013-09-11 01:57:36 +00:00
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2013-11-27 16:33:49 +00:00
|
|
|
* @property {Phaser.Game} game - A reference to the currently running Game.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2013-10-11 03:42:11 +00:00
|
|
|
this.game = game;
|
2013-12-19 03:49:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Tilemap} map - The Tilemap to which this layer is bound.
|
|
|
|
*/
|
|
|
|
this.map = tilemap;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} index - The index of this layer within the Tilemap.
|
|
|
|
*/
|
|
|
|
this.index = index;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {object} layer - The layer object within the Tilemap that this layer represents.
|
|
|
|
*/
|
|
|
|
this.layer = tilemap.layers[index];
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2013-12-17 05:07:00 +00:00
|
|
|
* @property {HTMLCanvasElement} canvas - The canvas to which this TilemapLayer draws.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2014-02-28 03:55:06 +00:00
|
|
|
this.canvas = Phaser.Canvas.create(width, height, '', true);
|
2014-03-21 18:04:24 +00:00
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2013-11-27 16:33:49 +00:00
|
|
|
* @property {CanvasRenderingContext2D} context - The 2d context of the canvas.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2013-10-11 03:42:11 +00:00
|
|
|
this.context = this.canvas.getContext('2d');
|
2013-10-01 12:54:29 +00:00
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2013-11-27 16:33:49 +00:00
|
|
|
* @property {PIXI.BaseTexture} baseTexture - Required Pixi var.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2013-10-11 03:42:11 +00:00
|
|
|
this.baseTexture = new PIXI.BaseTexture(this.canvas);
|
2013-10-01 12:54:29 +00:00
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2013-11-27 16:33:49 +00:00
|
|
|
* @property {PIXI.Texture} texture - Required Pixi var.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2013-10-11 03:42:11 +00:00
|
|
|
this.texture = new PIXI.Texture(this.baseTexture);
|
2013-10-01 12:54:29 +00:00
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Frame} textureFrame - Dimensions of the renderable area.
|
|
|
|
*/
|
2013-12-19 03:49:28 +00:00
|
|
|
this.textureFrame = new Phaser.Frame(0, 0, 0, width, height, 'tilemapLayer', game.rnd.uuid());
|
2013-10-11 17:18:27 +00:00
|
|
|
|
2014-03-03 05:19:46 +00:00
|
|
|
Phaser.Image.call(this, this.game, 0, 0, this.texture, this.textureFrame);
|
2013-12-19 03:49:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {string} name - The name of the layer.
|
|
|
|
*/
|
|
|
|
this.name = '';
|
2013-10-16 05:33:39 +00:00
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
|
|
|
* @property {number} type - The const type of this object.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-10-16 05:33:39 +00:00
|
|
|
this.type = Phaser.TILEMAPLAYER;
|
2013-10-11 03:42:11 +00:00
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
2013-12-17 05:07:00 +00:00
|
|
|
* An object that is fixed to the camera ignores the position of any ancestors in the display list and uses its x/y coordinates as offsets from the top left of the camera.
|
|
|
|
* @property {boolean} fixedToCamera - Fixes this object to the Camera.
|
2013-11-27 16:33:49 +00:00
|
|
|
* @default
|
|
|
|
*/
|
2013-10-16 05:33:39 +00:00
|
|
|
this.fixedToCamera = true;
|
2013-10-14 18:37:44 +00:00
|
|
|
|
2013-12-17 05:07:00 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} cameraOffset - If this object is fixed to the camera then use this Point to specify how far away from the Camera x/y it's rendered.
|
|
|
|
*/
|
2013-12-19 03:49:28 +00:00
|
|
|
this.cameraOffset = new Phaser.Point(0, 0);
|
2013-10-11 03:42:11 +00:00
|
|
|
|
2013-12-18 04:40:10 +00:00
|
|
|
/**
|
2014-01-14 00:31:58 +00:00
|
|
|
* @property {string} tileColor - If no tileset is given the tiles will be rendered as rectangles in this color. Provide in hex or rgb/rgba string format.
|
2013-12-18 04:40:10 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.tileColor = 'rgb(255, 255, 255)';
|
|
|
|
|
2013-12-17 05:07:00 +00:00
|
|
|
/**
|
2014-01-14 22:34:41 +00:00
|
|
|
* @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.
|
2013-12-17 05:07:00 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.debug = false;
|
|
|
|
|
2013-12-18 00:44:04 +00:00
|
|
|
/**
|
|
|
|
* @property {number} debugAlpha - If debug is true then the tileset is rendered with this alpha level, to make the tile edges clearer.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.debugAlpha = 0.5;
|
|
|
|
|
2013-12-18 04:40:10 +00:00
|
|
|
/**
|
|
|
|
* @property {string} debugColor - If debug is true this is the color used to outline the edges of collidable tiles. Provide in hex or rgb/rgba string format.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.debugColor = 'rgba(0, 255, 0, 1)';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {boolean} debugFill - If true the debug tiles are filled with debugFillColor AND stroked around.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.debugFill = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {string} debugFillColor - If debugFill is true this is the color used to fill the tiles. Provide in hex or rgb/rgba string format.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.debugFillColor = 'rgba(0, 255, 0, 0.2)';
|
|
|
|
|
2014-01-14 22:34:41 +00:00
|
|
|
/**
|
|
|
|
* @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)';
|
|
|
|
|
2013-12-18 04:40:10 +00:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
this.scrollFactorY = 1;
|
|
|
|
|
|
|
|
/**
|
2013-12-19 03:49:28 +00:00
|
|
|
* @property {boolean} dirty - Flag controlling when to re-render the layer.
|
2013-12-18 04:40:10 +00:00
|
|
|
*/
|
2013-12-19 03:49:28 +00:00
|
|
|
this.dirty = true;
|
2013-12-18 04:40:10 +00:00
|
|
|
|
2014-03-14 02:33:58 +00:00
|
|
|
/**
|
|
|
|
* @property {number} rayStepRate - When ray-casting against tiles this is the number of steps it will jump. For larger tile sizes you can increase this to improve performance.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.rayStepRate = 4;
|
|
|
|
|
2013-12-18 04:40:10 +00:00
|
|
|
/**
|
2014-03-23 10:35:31 +00:00
|
|
|
* @property {array} _results - Local render loop var to help avoid gc spikes.
|
2013-10-11 05:30:28 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache = {
|
|
|
|
|
|
|
|
cw: tilemap.tileWidth,
|
|
|
|
ch: tilemap.tileHeight,
|
|
|
|
ga: 1,
|
|
|
|
dx: 0,
|
|
|
|
dy: 0,
|
|
|
|
dw: 0,
|
|
|
|
dh: 0,
|
|
|
|
tx: 0,
|
|
|
|
ty: 0,
|
|
|
|
tw: 0,
|
|
|
|
th: 0,
|
|
|
|
tl: 0,
|
|
|
|
maxX: 0,
|
|
|
|
maxY: 0,
|
|
|
|
startX: 0,
|
|
|
|
startY: 0,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
prevX: 0,
|
|
|
|
prevY: 0
|
|
|
|
|
|
|
|
};
|
2013-10-11 05:30:28 +00:00
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
|
|
|
* @property {array} _results - Local render loop var to help avoid gc spikes.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._results = [];
|
|
|
|
|
2013-12-19 03:49:28 +00:00
|
|
|
this.updateMax();
|
2013-10-14 18:37:44 +00:00
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
};
|
|
|
|
|
2014-03-03 05:19:46 +00:00
|
|
|
Phaser.TilemapLayer.prototype = Object.create(Phaser.Image.prototype);
|
2013-10-16 05:33:39 +00:00
|
|
|
Phaser.TilemapLayer.prototype.constructor = Phaser.TilemapLayer;
|
2013-09-11 01:57:36 +00:00
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
2013-12-01 01:40:24 +00:00
|
|
|
* Automatically called by World.postUpdate. Handles cache updates.
|
2013-11-27 16:33:49 +00:00
|
|
|
*
|
2013-12-01 01:40:24 +00:00
|
|
|
* @method Phaser.TilemapLayer#postUpdate
|
2013-11-27 16:33:49 +00:00
|
|
|
* @memberof Phaser.TilemapLayer
|
|
|
|
*/
|
2013-12-01 01:40:24 +00:00
|
|
|
Phaser.TilemapLayer.prototype.postUpdate = function () {
|
2013-10-16 01:09:12 +00:00
|
|
|
|
2014-03-23 23:57:46 +00:00
|
|
|
// console.log('layer pu');
|
|
|
|
|
|
|
|
Phaser.Image.prototype.postUpdate.call(this);
|
2013-12-01 01:40:24 +00:00
|
|
|
|
2013-12-06 04:34:27 +00:00
|
|
|
// Stops you being able to auto-scroll the camera if it's not following a sprite
|
2013-11-07 18:44:04 +00:00
|
|
|
this.scrollX = this.game.camera.x * this.scrollFactorX;
|
|
|
|
this.scrollY = this.game.camera.y * this.scrollFactorY;
|
2013-10-16 01:09:12 +00:00
|
|
|
|
2013-10-16 05:33:39 +00:00
|
|
|
this.render();
|
2013-10-16 01:09:12 +00:00
|
|
|
|
2014-03-21 18:04:24 +00:00
|
|
|
// Fixed to Camera?
|
2014-03-22 08:32:33 +00:00
|
|
|
if (this._cache[7] === 1)
|
|
|
|
{
|
2014-03-21 18:04:24 +00:00
|
|
|
this.position.x = (this.game.camera.view.x + this.cameraOffset.x) / this.game.camera.scale.x;
|
|
|
|
this.position.y = (this.game.camera.view.y + this.cameraOffset.y) / this.game.camera.scale.y;
|
2014-03-22 08:32:33 +00:00
|
|
|
}
|
2014-03-21 18:04:24 +00:00
|
|
|
|
|
|
|
// Update any Children
|
|
|
|
// for (var i = 0, len = this.children.length; i < len; i++)
|
|
|
|
// {
|
|
|
|
// this.children[i].postUpdate();
|
|
|
|
// }
|
|
|
|
|
2013-10-16 05:33:39 +00:00
|
|
|
}
|
2013-10-16 01:09:12 +00:00
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
|
|
|
* Sets the world size to match the size of this layer.
|
|
|
|
*
|
|
|
|
* @method Phaser.TilemapLayer#resizeWorld
|
|
|
|
* @memberof Phaser.TilemapLayer
|
|
|
|
*/
|
2013-10-16 05:33:39 +00:00
|
|
|
Phaser.TilemapLayer.prototype.resizeWorld = function () {
|
2013-10-16 01:09:12 +00:00
|
|
|
|
2013-12-22 04:27:12 +00:00
|
|
|
this.game.world.setBounds(0, 0, this.layer.widthInPixels, this.layer.heightInPixels);
|
2013-12-18 04:40:10 +00:00
|
|
|
|
2013-10-16 05:33:39 +00:00
|
|
|
}
|
2013-10-15 03:28:16 +00:00
|
|
|
|
2013-11-07 18:44:04 +00:00
|
|
|
/**
|
2013-12-09 16:40:48 +00:00
|
|
|
* Take an x coordinate that doesn't account for scrollFactorX and 'fix' it
|
2013-11-27 16:33:49 +00:00
|
|
|
* into a scrolled local space. Used primarily internally
|
|
|
|
* @method Phaser.TilemapLayer#_fixX
|
|
|
|
* @memberof Phaser.TilemapLayer
|
|
|
|
* @private
|
|
|
|
* @param {number} x - x coordinate in camera space
|
|
|
|
* @return {number} x coordinate in scrollFactor-adjusted dimensions
|
|
|
|
*/
|
2013-11-13 20:57:09 +00:00
|
|
|
Phaser.TilemapLayer.prototype._fixX = function(x) {
|
|
|
|
|
2013-12-09 16:40:48 +00:00
|
|
|
if (x < 0)
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
if (this.scrollFactorX === 1)
|
2013-11-13 20:57:09 +00:00
|
|
|
{
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
return this.cache.x + (x - (this.cache.x / this.scrollFactorX));
|
2013-11-13 20:57:09 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-11-07 18:44:04 +00:00
|
|
|
/**
|
2013-12-09 16:40:48 +00:00
|
|
|
* Take an x coordinate that _does_ account for scrollFactorX and 'unfix' it
|
2013-11-27 16:33:49 +00:00
|
|
|
* back to camera space. Used primarily internally
|
|
|
|
* @method Phaser.TilemapLayer#_unfixX
|
|
|
|
* @memberof Phaser.TilemapLayer
|
|
|
|
* @private
|
|
|
|
* @param {number} x - x coordinate in scrollFactor-adjusted dimensions
|
|
|
|
* @return {number} x coordinate in camera space
|
|
|
|
*/
|
2013-11-13 20:57:09 +00:00
|
|
|
Phaser.TilemapLayer.prototype._unfixX = function(x) {
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
if (this.scrollFactorX === 1)
|
2013-11-13 20:57:09 +00:00
|
|
|
{
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
return (this.cache.x / this.scrollFactorX) + (x - this.cache.x);
|
2013-11-13 20:57:09 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-11-07 18:44:04 +00:00
|
|
|
/**
|
2013-11-27 16:33:49 +00:00
|
|
|
* Take a y coordinate that doesn't account for scrollFactorY and 'fix' it
|
|
|
|
* into a scrolled local space. Used primarily internally
|
|
|
|
* @method Phaser.TilemapLayer#_fixY
|
|
|
|
* @memberof Phaser.TilemapLayer
|
|
|
|
* @private
|
|
|
|
* @param {number} y - y coordinate in camera space
|
|
|
|
* @return {number} y coordinate in scrollFactor-adjusted dimensions
|
|
|
|
*/
|
2013-11-13 20:57:09 +00:00
|
|
|
Phaser.TilemapLayer.prototype._fixY = function(y) {
|
|
|
|
|
2013-12-09 16:40:48 +00:00
|
|
|
if (y < 0)
|
|
|
|
{
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
if (this.scrollFactorY === 1)
|
2013-11-13 20:57:09 +00:00
|
|
|
{
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
return this.cache.y + (y - (this.cache.y / this.scrollFactorY));
|
2013-11-13 20:57:09 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-11-07 18:44:04 +00:00
|
|
|
/**
|
2013-11-27 16:33:49 +00:00
|
|
|
* Take a y coordinate that _does_ account for scrollFactorY and 'unfix' it
|
|
|
|
* back to camera space. Used primarily internally
|
|
|
|
* @method Phaser.TilemapLayer#_unfixY
|
|
|
|
* @memberof Phaser.TilemapLayer
|
|
|
|
* @private
|
|
|
|
* @param {number} y - y coordinate in scrollFactor-adjusted dimensions
|
|
|
|
* @return {number} y coordinate in camera space
|
|
|
|
*/
|
2013-11-13 20:57:09 +00:00
|
|
|
Phaser.TilemapLayer.prototype._unfixY = function(y) {
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
if (this.scrollFactorY === 1)
|
2013-11-13 20:57:09 +00:00
|
|
|
{
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
return (this.cache.y / this.scrollFactorY) + (y - this.cache.y);
|
2013-11-13 20:57:09 +00:00
|
|
|
|
|
|
|
}
|
2013-11-07 18:44:04 +00:00
|
|
|
|
2013-10-16 20:25:51 +00:00
|
|
|
/**
|
|
|
|
* Convert a pixel value to a tile coordinate.
|
2013-11-27 16:33:49 +00:00
|
|
|
* @method Phaser.TilemapLayer#getTileX
|
|
|
|
* @memberof Phaser.TilemapLayer
|
2013-10-16 20:25:51 +00:00
|
|
|
* @param {number} x - X position of the point in target tile.
|
2013-11-27 16:33:49 +00:00
|
|
|
* @return {Phaser.Tile} The tile with specific properties.
|
2013-10-16 20:25:51 +00:00
|
|
|
*/
|
|
|
|
Phaser.TilemapLayer.prototype.getTileX = function (x) {
|
|
|
|
|
2013-12-19 03:49:28 +00:00
|
|
|
// var tileWidth = this.tileWidth * this.scale.x;
|
2013-10-16 20:25:51 +00:00
|
|
|
|
2013-12-19 03:49:28 +00:00
|
|
|
return this.game.math.snapToFloor(this._fixX(x), this.map.tileWidth) / this.map.tileWidth;
|
2013-10-16 20:25:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a pixel value to a tile coordinate.
|
2013-11-27 16:33:49 +00:00
|
|
|
* @method Phaser.TilemapLayer#getTileY
|
|
|
|
* @memberof Phaser.TilemapLayer
|
|
|
|
* @param {number} y - Y position of the point in target tile.
|
|
|
|
* @return {Phaser.Tile} The tile with specific properties.
|
2013-10-16 20:25:51 +00:00
|
|
|
*/
|
|
|
|
Phaser.TilemapLayer.prototype.getTileY = function (y) {
|
|
|
|
|
2013-12-19 03:49:28 +00:00
|
|
|
// var tileHeight = this.tileHeight * this.scale.y;
|
2013-10-16 20:25:51 +00:00
|
|
|
|
2013-12-19 03:49:28 +00:00
|
|
|
return this.game.math.snapToFloor(this._fixY(y), this.map.tileHeight) / this.map.tileHeight;
|
2013-10-16 20:25:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
|
|
|
* Convert a pixel value to a tile coordinate.
|
|
|
|
* @method Phaser.TilemapLayer#getTileXY
|
|
|
|
* @memberof Phaser.TilemapLayer
|
|
|
|
* @param {number} x - X position of the point in target tile.
|
|
|
|
* @param {number} y - Y position of the point in target tile.
|
2013-12-19 03:49:28 +00:00
|
|
|
* @param {Phaser.Point|object} point - The Point object to set the x and y values on.
|
|
|
|
* @return {Phaser.Point|object} A Point object with its x and y properties set.
|
2013-11-27 16:33:49 +00:00
|
|
|
*/
|
2013-10-16 20:25:51 +00:00
|
|
|
Phaser.TilemapLayer.prototype.getTileXY = function (x, y, point) {
|
|
|
|
|
|
|
|
point.x = this.getTileX(x);
|
|
|
|
point.y = this.getTileY(y);
|
|
|
|
|
|
|
|
return point;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-03-14 00:19:45 +00:00
|
|
|
/**
|
|
|
|
* Gets all tiles that intersect with the given line.
|
|
|
|
*
|
2014-03-14 02:33:58 +00:00
|
|
|
* @method Phaser.TilemapLayer#getRayCastTiles
|
2014-03-14 00:19:45 +00:00
|
|
|
* @memberof Phaser.TilemapLayer
|
|
|
|
* @param {Phaser.Line} line - The line used to determine which tiles to return.
|
2014-03-14 02:33:58 +00:00
|
|
|
* @param {number} [stepRate] - How many steps through the ray will we check? If undefined or null it uses TilemapLayer.rayStepRate.
|
|
|
|
* @param {boolean} [collides=false] - If true only return tiles that collide on one or more faces.
|
|
|
|
* @param {boolean} [interestingFace=false] - If true only return tiles that have interesting faces.
|
2014-03-14 00:19:45 +00:00
|
|
|
* @return {array<Phaser.Tile>} An array of Phaser.Tiles.
|
|
|
|
*/
|
2014-03-14 02:33:58 +00:00
|
|
|
Phaser.TilemapLayer.prototype.getRayCastTiles = function (line, stepRate, collides, interestingFace) {
|
2014-03-06 06:27:16 +00:00
|
|
|
|
2014-03-14 02:33:58 +00:00
|
|
|
if (typeof stepRate === 'undefined' || stepRate === null) { stepRate = this.rayStepRate; }
|
|
|
|
if (typeof collides === 'undefined') { collides = false; }
|
|
|
|
if (typeof interestingFace === 'undefined') { interestingFace = false; }
|
|
|
|
|
|
|
|
// First get all tiles that touch the bounds of the line
|
|
|
|
var tiles = this.getTiles(line.x, line.y, line.width, line.height, collides, interestingFace);
|
2014-03-06 06:27:16 +00:00
|
|
|
|
2014-03-14 02:33:58 +00:00
|
|
|
if (tiles.length === 0)
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
2014-03-06 06:27:16 +00:00
|
|
|
|
2014-03-14 02:33:58 +00:00
|
|
|
// Now we only want the tiles that intersect with the points on this line
|
|
|
|
var coords = line.coordinatesOnLine(stepRate);
|
|
|
|
var total = coords.length;
|
|
|
|
var results = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < tiles.length; i++)
|
|
|
|
{
|
|
|
|
for (var t = 0; t < total; t++)
|
|
|
|
{
|
|
|
|
if (tiles[i].containsPoint(coords[t][0], coords[t][1]))
|
|
|
|
{
|
|
|
|
results.push(tiles[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
2014-03-06 06:27:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-16 05:33:39 +00:00
|
|
|
/**
|
2013-12-17 05:07:00 +00:00
|
|
|
* Get all tiles that exist within the given area, defined by the top-left corner, width and height. Values given are in pixels, not tiles.
|
2013-11-27 16:33:49 +00:00
|
|
|
* @method Phaser.TilemapLayer#getTiles
|
|
|
|
* @memberof Phaser.TilemapLayer
|
2013-12-17 05:07:00 +00:00
|
|
|
* @param {number} x - X position of the top left corner.
|
|
|
|
* @param {number} y - Y position of the top left corner.
|
|
|
|
* @param {number} width - Width of the area to get.
|
|
|
|
* @param {number} height - Height of the area to get.
|
2013-12-05 18:12:16 +00:00
|
|
|
* @param {boolean} [collides=false] - If true only return tiles that collide on one or more faces.
|
2014-03-13 22:49:08 +00:00
|
|
|
* @param {boolean} [interestingFace=false] - If true only return tiles that have interesting faces.
|
2014-03-14 00:19:45 +00:00
|
|
|
* @return {array<Phaser.Tile>} An array of Phaser.Tiles.
|
2013-10-16 05:33:39 +00:00
|
|
|
*/
|
2014-03-13 22:49:08 +00:00
|
|
|
Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides, interestingFace) {
|
2013-12-17 05:07:00 +00:00
|
|
|
|
|
|
|
// Should we only get tiles that have at least one of their collision flags set? (true = yes, false = no just get them all)
|
|
|
|
if (typeof collides === 'undefined') { collides = false; }
|
2014-03-13 22:49:08 +00:00
|
|
|
if (typeof interestingFace === 'undefined') { interestingFace = false; }
|
2013-12-17 05:07:00 +00:00
|
|
|
|
|
|
|
// adjust the x,y coordinates for scrollFactor
|
|
|
|
x = this._fixX(x);
|
|
|
|
y = this._fixY(y);
|
|
|
|
|
2013-12-19 03:49:28 +00:00
|
|
|
if (width > this.layer.widthInPixels)
|
2013-12-17 05:07:00 +00:00
|
|
|
{
|
2013-12-19 03:49:28 +00:00
|
|
|
width = this.layer.widthInPixels;
|
2013-12-17 05:07:00 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 03:49:28 +00:00
|
|
|
if (height > this.layer.heightInPixels)
|
2013-12-17 05:07:00 +00:00
|
|
|
{
|
2013-12-19 03:49:28 +00:00
|
|
|
height = this.layer.heightInPixels;
|
2013-12-17 05:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the pixel values into tile coordinates
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.tx = this.game.math.snapToFloor(x, this.cache.cw) / this.cache.cw;
|
|
|
|
this.cache.ty = this.game.math.snapToFloor(y, this.cache.ch) / this.cache.ch;
|
|
|
|
this.cache.tw = (this.game.math.snapToCeil(width, this.cache.cw) + this.cache.cw) / this.cache.cw;
|
|
|
|
this.cache.th = (this.game.math.snapToCeil(height, this.cache.ch) + this.cache.ch) / this.cache.ch;
|
2013-12-17 05:07:00 +00:00
|
|
|
|
2013-12-05 18:12:16 +00:00
|
|
|
// This should apply the layer x/y here
|
2014-03-13 21:14:10 +00:00
|
|
|
this._results.length = 0;
|
2013-10-16 05:33:39 +00:00
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
for (var wy = this.cache.ty; wy < this.cache.ty + this.cache.th; wy++)
|
2013-10-16 05:33:39 +00:00
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
for (var wx = this.cache.tx; wx < this.cache.tx + this.cache.tw; wx++)
|
2013-10-15 03:28:16 +00:00
|
|
|
{
|
2013-10-16 05:33:39 +00:00
|
|
|
if (this.layer.data[wy] && this.layer.data[wy][wx])
|
2013-10-15 03:28:16 +00:00
|
|
|
{
|
2014-03-13 22:49:08 +00:00
|
|
|
if ((!collides && !interestingFace) || this.layer.data[wy][wx].isInteresting(collides, interestingFace))
|
2013-10-15 03:28:16 +00:00
|
|
|
{
|
2014-03-06 06:27:16 +00:00
|
|
|
this._results.push(this.layer.data[wy][wx]);
|
2013-10-15 03:28:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-16 05:33:39 +00:00
|
|
|
}
|
2013-10-15 03:28:16 +00:00
|
|
|
|
2013-10-16 05:33:39 +00:00
|
|
|
return this._results;
|
2013-10-14 18:37:44 +00:00
|
|
|
|
2013-10-16 05:33:39 +00:00
|
|
|
}
|
2013-10-11 05:30:28 +00:00
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
|
|
|
* Internal function to update maximum values.
|
|
|
|
* @method Phaser.TilemapLayer#updateMax
|
|
|
|
* @memberof Phaser.TilemapLayer
|
|
|
|
*/
|
2013-10-16 05:33:39 +00:00
|
|
|
Phaser.TilemapLayer.prototype.updateMax = function () {
|
2013-10-11 05:30:28 +00:00
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.maxX = this.game.math.ceil(this.canvas.width / this.map.tileWidth) + 1;
|
|
|
|
this.cache.maxY = this.game.math.ceil(this.canvas.height / this.map.tileHeight) + 1;
|
2013-10-11 05:30:28 +00:00
|
|
|
|
2013-10-16 05:33:39 +00:00
|
|
|
if (this.layer)
|
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
if (this.cache.maxX > this.layer.width)
|
2013-10-11 19:02:12 +00:00
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.maxX = this.layer.width;
|
2013-10-11 05:30:28 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
if (this.cache.maxY > this.layer.height)
|
2013-10-16 05:33:39 +00:00
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.maxY = this.layer.height;
|
2013-10-16 05:33:39 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-11 05:30:28 +00:00
|
|
|
|
2013-10-16 05:33:39 +00:00
|
|
|
this.dirty = true;
|
2013-10-11 05:30:28 +00:00
|
|
|
|
2013-10-16 05:33:39 +00:00
|
|
|
}
|
2013-10-11 05:30:28 +00:00
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
|
|
|
* Renders the tiles to the layer canvas and pushes to the display.
|
|
|
|
* @method Phaser.TilemapLayer#render
|
|
|
|
* @memberof Phaser.TilemapLayer
|
|
|
|
*/
|
2013-10-16 05:33:39 +00:00
|
|
|
Phaser.TilemapLayer.prototype.render = function () {
|
2013-10-13 00:29:57 +00:00
|
|
|
|
2014-03-03 05:19:46 +00:00
|
|
|
if (this.layer.dirty)
|
2014-01-31 05:42:20 +00:00
|
|
|
{
|
|
|
|
this.dirty = true;
|
|
|
|
}
|
2013-10-16 20:25:51 +00:00
|
|
|
|
2014-01-31 05:42:20 +00:00
|
|
|
if (!this.dirty || !this.visible)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-10-11 05:30:28 +00:00
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.prevX = this.cache.dx;
|
|
|
|
this.cache.prevY = this.cache.dy;
|
2013-10-11 05:30:28 +00:00
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.dx = -(this.cache.x - (this.cache.startX * this.map.tileWidth));
|
|
|
|
this.cache.dy = -(this.cache.y - (this.cache.startY * this.map.tileHeight));
|
2013-10-11 05:30:28 +00:00
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.tx = this.cache.dx;
|
|
|
|
this.cache.ty = this.cache.dy;
|
2013-10-11 05:30:28 +00:00
|
|
|
|
2013-12-06 04:34:27 +00:00
|
|
|
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
2014-01-31 03:32:12 +00:00
|
|
|
|
2013-12-19 03:49:28 +00:00
|
|
|
this.context.fillStyle = this.tileColor;
|
|
|
|
|
|
|
|
var tile;
|
|
|
|
var set;
|
2013-12-17 05:07:00 +00:00
|
|
|
|
|
|
|
if (this.debug)
|
|
|
|
{
|
2013-12-18 00:44:04 +00:00
|
|
|
this.context.globalAlpha = this.debugAlpha;
|
2013-12-17 05:07:00 +00:00
|
|
|
}
|
2013-10-11 17:18:27 +00:00
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
for (var y = this.cache.startY, lenY = this.cache.startY + this.cache.maxY; y < lenY; y++)
|
2014-03-03 05:19:46 +00:00
|
|
|
{
|
|
|
|
this._column = this.layer.data[y];
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
for (var x = this.cache.startX, lenX = this.cache.startX + this.cache.maxX; x < lenX; x++)
|
2014-03-03 05:19:46 +00:00
|
|
|
{
|
|
|
|
if (this._column[x])
|
|
|
|
{
|
|
|
|
tile = this._column[x];
|
|
|
|
|
2014-03-21 18:04:24 +00:00
|
|
|
set = this.map.tilesets[this.map.tiles[tile.index][2]];
|
2014-03-03 05:19:46 +00:00
|
|
|
|
|
|
|
if (this.debug === false && tile.alpha !== this.context.globalAlpha)
|
|
|
|
{
|
|
|
|
this.context.globalAlpha = tile.alpha;
|
|
|
|
}
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
set.draw(this.context, Math.floor(this.cache.tx), Math.floor(this.cache.ty), tile.index);
|
2014-03-03 05:19:46 +00:00
|
|
|
|
2014-03-14 02:33:58 +00:00
|
|
|
if (tile.debug)
|
|
|
|
{
|
|
|
|
this.context.fillStyle = 'rgba(0, 255, 0, 0.4)';
|
2014-03-23 10:35:31 +00:00
|
|
|
this.context.fillRect(Math.floor(this.cache.tx), Math.floor(this.cache.ty), this.map.tileWidth, this.map.tileHeight);
|
2014-03-14 02:33:58 +00:00
|
|
|
}
|
2014-03-03 05:19:46 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.tx += this.map.tileWidth;
|
2014-03-03 05:19:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.tx = this.cache.dx;
|
|
|
|
this.cache.ty += this.map.tileHeight;
|
2014-03-03 05:19:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.debug)
|
|
|
|
{
|
|
|
|
this.context.globalAlpha = 1;
|
|
|
|
this.renderDebug();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.game.renderType === Phaser.WEBGL)
|
|
|
|
{
|
|
|
|
// PIXI.updateWebGLTexture(this.baseTexture, renderSession.gl);
|
2014-03-13 16:49:52 +00:00
|
|
|
PIXI.updateWebGLTexture(this.baseTexture, this.game.renderer.gl);
|
2013-10-11 17:18:27 +00:00
|
|
|
}
|
|
|
|
|
2013-10-16 05:33:39 +00:00
|
|
|
this.dirty = false;
|
2013-12-19 03:49:28 +00:00
|
|
|
this.layer.dirty = false;
|
2013-10-16 20:25:51 +00:00
|
|
|
|
2013-10-16 05:33:39 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
2013-10-11 05:30:28 +00:00
|
|
|
|
2013-12-18 04:40:10 +00:00
|
|
|
/**
|
|
|
|
* Renders a collision debug overlay on-top of the canvas. Called automatically by render when debug = true.
|
|
|
|
* @method Phaser.TilemapLayer#renderDebug
|
|
|
|
* @memberof Phaser.TilemapLayer
|
|
|
|
*/
|
2013-12-18 00:44:04 +00:00
|
|
|
Phaser.TilemapLayer.prototype.renderDebug = function () {
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.tx = this.cache.dx;
|
|
|
|
this.cache.ty = this.cache.dy;
|
2013-12-18 00:44:04 +00:00
|
|
|
|
2013-12-18 04:40:10 +00:00
|
|
|
this.context.strokeStyle = this.debugColor;
|
|
|
|
this.context.fillStyle = this.debugFillColor;
|
2013-12-18 00:44:04 +00:00
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
for (var y = this.cache.startY, lenY = this.cache.startY + this.cache.maxY; y < lenY; y++)
|
2013-12-18 00:44:04 +00:00
|
|
|
{
|
|
|
|
this._column = this.layer.data[y];
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
for (var x = this.cache.startX, lenX = this.cache.startX + this.cache.maxX; x < lenX; x++)
|
2013-12-18 00:44:04 +00:00
|
|
|
{
|
|
|
|
var tile = this._column[x];
|
|
|
|
|
|
|
|
if (tile && (tile.faceTop || tile.faceBottom || tile.faceLeft || tile.faceRight))
|
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.tx = Math.floor(this.cache.tx);
|
2013-12-18 00:44:04 +00:00
|
|
|
|
2013-12-18 04:40:10 +00:00
|
|
|
if (this.debugFill)
|
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.context.fillRect(this.cache.tx, this.cache.ty, this.cache.cw, this.cache.ch);
|
2013-12-18 04:40:10 +00:00
|
|
|
}
|
2013-12-18 00:44:04 +00:00
|
|
|
|
|
|
|
this.context.beginPath();
|
|
|
|
|
|
|
|
if (tile.faceTop)
|
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.context.moveTo(this.cache.tx, this.cache.ty);
|
|
|
|
this.context.lineTo(this.cache.tx + this.cache.cw, this.cache.ty);
|
2013-12-18 00:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tile.faceBottom)
|
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.context.moveTo(this.cache.tx, this.cache.ty + this.cache.ch);
|
|
|
|
this.context.lineTo(this.cache.tx + this.cache.cw, this.cache.ty + this.cache.ch);
|
2013-12-18 00:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tile.faceLeft)
|
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.context.moveTo(this.cache.tx, this.cache.ty);
|
|
|
|
this.context.lineTo(this.cache.tx, this.cache.ty + this.cache.ch);
|
2013-12-18 00:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tile.faceRight)
|
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.context.moveTo(this.cache.tx + this.cache.cw, this.cache.ty);
|
|
|
|
this.context.lineTo(this.cache.tx + this.cache.cw, this.cache.ty + this.cache.ch);
|
2013-12-18 00:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.context.stroke();
|
|
|
|
}
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.tx += this.map.tileWidth;
|
2013-12-18 00:44:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.tx = this.cache.dx;
|
|
|
|
this.cache.ty += this.map.tileHeight;
|
2013-12-18 00:44:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
|
|
|
* @name Phaser.TilemapLayer#scrollX
|
|
|
|
* @property {number} scrollX - Scrolls the map horizontally or returns the current x position.
|
|
|
|
*/
|
2013-10-16 05:33:39 +00:00
|
|
|
Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollX", {
|
2013-10-11 17:18:27 +00:00
|
|
|
|
|
|
|
get: function () {
|
2014-03-23 10:35:31 +00:00
|
|
|
return this.cache.x;
|
2013-10-11 17:18:27 +00:00
|
|
|
},
|
2013-09-11 01:57:36 +00:00
|
|
|
|
2013-10-11 17:18:27 +00:00
|
|
|
set: function (value) {
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
if (value !== this.cache.x && value >= 0 && this.layer.widthInPixels > this.width)
|
2013-10-11 17:18:27 +00:00
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.x = value;
|
2013-12-06 04:34:27 +00:00
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
if (this.cache.x > (this.layer.widthInPixels - this.width))
|
2013-10-11 19:02:12 +00:00
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.x = this.layer.widthInPixels - this.width;
|
2013-10-11 19:02:12 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.startX = this.game.math.floor(this.cache.x / this.map.tileWidth);
|
2013-10-11 19:02:12 +00:00
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
if (this.cache.startX < 0)
|
2013-10-11 19:02:12 +00:00
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.startX = 0;
|
2013-10-11 19:02:12 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
if (this.cache.startX + this.cache.maxX > this.layer.width)
|
2013-10-11 19:02:12 +00:00
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.startX = this.layer.width - this.cache.maxX;
|
2013-10-11 19:02:12 +00:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:18:27 +00:00
|
|
|
this.dirty = true;
|
|
|
|
}
|
2013-09-11 01:57:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:18:27 +00:00
|
|
|
});
|
|
|
|
|
2013-11-27 16:33:49 +00:00
|
|
|
/**
|
|
|
|
* @name Phaser.TilemapLayer#scrollY
|
|
|
|
* @property {number} scrollY - Scrolls the map vertically or returns the current y position.
|
|
|
|
*/
|
2013-10-16 05:33:39 +00:00
|
|
|
Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollY", {
|
2013-10-11 17:18:27 +00:00
|
|
|
|
|
|
|
get: function () {
|
2014-03-23 10:35:31 +00:00
|
|
|
return this.cache.y;
|
2013-10-11 17:18:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
if (value !== this.cache.y && value >= 0 && this.layer.heightInPixels > this.height)
|
2013-10-11 17:18:27 +00:00
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.y = value;
|
2013-10-11 19:02:12 +00:00
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
if (this.cache.y > (this.layer.heightInPixels - this.height))
|
2013-10-11 19:02:12 +00:00
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.y = this.layer.heightInPixels - this.height;
|
2013-10-11 19:02:12 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.startY = this.game.math.floor(this.cache.y / this.map.tileHeight);
|
2013-10-11 19:02:12 +00:00
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
if (this.cache.startY < 0)
|
2013-10-11 19:02:12 +00:00
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.startY = 0;
|
2013-10-11 19:02:12 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
if (this.cache.startY + this.cache.maxY > this.layer.height)
|
2013-10-11 19:02:12 +00:00
|
|
|
{
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.startY = this.layer.height - this.cache.maxY;
|
2013-10-11 19:02:12 +00:00
|
|
|
}
|
|
|
|
|
2013-10-11 17:18:27 +00:00
|
|
|
this.dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-09-12 03:24:01 +00:00
|
|
|
|
2013-10-11 17:18:27 +00:00
|
|
|
});
|
2013-12-19 05:09:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Phaser.TilemapLayer#collisionWidth
|
|
|
|
* @property {number} collisionWidth - The width of the collision tiles.
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.TilemapLayer.prototype, "collisionWidth", {
|
|
|
|
|
|
|
|
get: function () {
|
2014-03-23 10:35:31 +00:00
|
|
|
return this.cache.cw;
|
2013-12-19 05:09:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.cw = value;
|
2013-12-19 05:09:49 +00:00
|
|
|
|
|
|
|
this.dirty = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Phaser.TilemapLayer#collisionHeight
|
|
|
|
* @property {number} collisionHeight - The height of the collision tiles.
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.TilemapLayer.prototype, "collisionHeight", {
|
|
|
|
|
|
|
|
get: function () {
|
2014-03-23 10:35:31 +00:00
|
|
|
return this.cache.ch;
|
2013-12-19 05:09:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
2014-03-23 10:35:31 +00:00
|
|
|
this.cache.ch = value;
|
2013-12-19 05:09:49 +00:00
|
|
|
|
|
|
|
this.dirty = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|