diff --git a/README.md b/README.md index 9e808eefc..04a3ef27c 100644 --- a/README.md +++ b/README.md @@ -329,6 +329,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/ * TilemapLayer.getRayCastTiles has been moved to Tilemap.getRayCastTiles. * TilemapLayer.rayStepRate has been moved to Tilemap.rayStepRate. * TilemapLayer.getTiles has been moved to Tilemap.getTiles. +* The private methods `TilemapLayer._fixX`, `_unfixX`, `_fixY` and `_unfixY` have been moved to `Tilemap. ### Bug Fixes diff --git a/src/pixi/extras/Tilemap.js b/src/pixi/extras/Tilemap.js index 0b20e19e5..753d96eda 100644 --- a/src/pixi/extras/Tilemap.js +++ b/src/pixi/extras/Tilemap.js @@ -362,9 +362,9 @@ PIXI.Tilemap.prototype._renderWholeTilemap = function (renderSession) { gl.uniform2f(shader.uOffset, renderSession.offset.x / this.game.width * 2, -renderSession.offset.y / this.game.height * 2); // set the clipping limits - gl.uniform2f(shader.uClipOffset, this._offset.x / this.game.width * 2, this._offset.y / this.game.height * 2); - gl.uniform2f(shader.uClipLoc, this._offset.x, this._offset.y); - gl.uniform2f(shader.uClipLimit, this._offset.x + this._displayWidth, this.game.height - (this._offset.y + this._displayHeight)); + gl.uniform2f(shader.uClipOffset, this.position.x / this.game.width * 2, this.position.y / this.game.height * 2); + gl.uniform2f(shader.uClipLoc, this.position.x, this.position.y); + gl.uniform2f(shader.uClipLimit, this.position.x + this._displayWidth, this.game.height - (this.position.y + this._displayHeight)); // set the offset in screen units to the center of the screen // and flip the GL y coordinate to be zero at the top diff --git a/src/tilemap/Tilemap.js b/src/tilemap/Tilemap.js index 294638ce7..06822db21 100644 --- a/src/tilemap/Tilemap.js +++ b/src/tilemap/Tilemap.js @@ -2107,6 +2107,150 @@ Phaser.Tilemap.prototype = { }, + /** + * Take an x coordinate that doesn't account for scrollFactorX and 'fix' it into a scrolled local space. + * + * @method Phaser.Tilemap#_fixX + * @private + * @param {number} x - x coordinate in camera space + * @return {number} x coordinate in scrollFactor-adjusted dimensions + */ + _fixX: function (x) { + + var layer = this.layer; + + if (layer.scrollFactorX === 1 || (layer.scrollFactorX === 0 && layer.position.x === 0)) + { + return x; + } + + // This executes if the scrollFactorX is 0 and the x position of the tilemap is off from standard. + if (layer.scrollFactorX === 0 && layer.position.x !== 0) + { + return x - layer.position.x; + } + + return layer._scrollX + (x - (layer._scrollX / layer.scrollFactorX)); + + }; + + /** + * Take an x coordinate that _does_ account for scrollFactorX and 'unfix' it back to camera space. + * + * @method Phaser.Tilemap#_unfixX + * @private + * @param {number} x - x coordinate in scrollFactor-adjusted dimensions + * @return {number} x coordinate in camera space + */ + _unfixX: function (x) { + + var layer = this.layer; + + if (layer.scrollFactorX === 1) + { + return x; + } + + return (layer._scrollX / layer.scrollFactorX) + (x - layer._scrollX); + + }, + + /** + * Take a y coordinate that doesn't account for scrollFactorY and 'fix' it into a scrolled local space. + * + * @method Phaser.Tilemap#_fixY + * @private + * @param {number} y - y coordinate in camera space + * @return {number} y coordinate in scrollFactor-adjusted dimensions + */ + _fixY: function (y) { + + var layer = this.layer; + + if (layer.scrollFactorY === 1 || (layer.scrollFactorY === 0 && layer.position.y === 0)) + { + return y; + } + + // This executes if the scrollFactorY is 0 and the y position of the tilemap is off from standard. + if (layer.scrollFactorY === 0 && layer.position.y !== 0) + { + return y - layer.position.y; + } + + return layer._scrollY + (y - (layer._scrollY / layer.scrollFactorY)); + + }, + + /** + * Take a y coordinate that _does_ account for scrollFactorY and 'unfix' it back to camera space. + * + * @method Phaser.Tilemap#_unfixY + * @private + * @param {number} y - y coordinate in scrollFactor-adjusted dimensions + * @return {number} y coordinate in camera space + */ + _unfixY: function (y) { + + var layer = this.layer; + + if (layer.scrollFactorY === 1) + { + return y; + } + + return (layer._scrollY / layer.scrollFactorY) + (y - layer._scrollY); + + }, + + /** + * Convert a pixel value to a tile coordinate. + * + * @method Phaser.Tilemap#getTileX + * @param {number} x - X position of the point in target tile (in pixels). + * @return {integer} The X map location of the tile. + */ + getTileX: function (x) { + + var layer = this.layer; + + return Math.floor(this._fixX(x) / layer._mc.tileWidth); + + }, + + /** + * Convert a pixel value to a tile coordinate. + * + * @method Phaser.Tilemap#getTileY + * @param {number} y - Y position of the point in target tile (in pixels). + * @return {integer} The Y map location of the tile. + */ + getTileY: function (y) { + + var layer = this.layer; + + return Math.floor(this._fixY(y) / layer._mc.tileHeight); + + }, + + /** + * Convert a pixel coordinate to a tile coordinate. + * + * @method Phaser.Tilemap#getTileXY + * @param {number} x - X position of the point in target tile (in pixels). + * @param {number} y - Y position of the point in target tile (in pixels). + * @param {(Phaser.Point|object)} point - The Point/object to update. + * @return {(Phaser.Point|object)} A Point/object with its `x` and `y` properties set. + */ + getTileXY: function (x, y, point) { + + point.x = this.getTileX(x); + point.y = this.getTileY(y); + + return point; + + }, + /** * Removes all layer data from this tile map and nulls the game reference. * Note: You are responsible for destroying any TilemapLayer objects you generated yourself, as Tilemap doesn't keep a reference to them. diff --git a/src/tilemap/TilemapLayer.js b/src/tilemap/TilemapLayer.js index 4e09ffa2f..6dd88eba5 100644 --- a/src/tilemap/TilemapLayer.js +++ b/src/tilemap/TilemapLayer.js @@ -397,144 +397,6 @@ Phaser.TilemapLayer.prototype.resizeWorld = function () { }; -/** -* Take an x coordinate that doesn't account for scrollFactorX and 'fix' it into a scrolled local space. -* -* @method Phaser.TilemapLayer#_fixX -* @private -* @param {number} x - x coordinate in camera space -* @return {number} x coordinate in scrollFactor-adjusted dimensions -*/ -Phaser.TilemapLayer.prototype._fixX = function (x) { - - if (this.scrollFactorX === 1 || (this.scrollFactorX === 0 && this.position.x === 0)) - { - return x; - } - - // This executes if the scrollFactorX is 0 and the x position of the tilemap is off from standard. - if (this.scrollFactorX === 0 && this.position.x !== 0) - { - return x - this.position.x; - } - - return this._scrollX + (x - (this._scrollX / this.scrollFactorX)); - -}; - -/** -* Take an x coordinate that _does_ account for scrollFactorX and 'unfix' it back to camera space. -* -* @method Phaser.TilemapLayer#_unfixX -* @private -* @param {number} x - x coordinate in scrollFactor-adjusted dimensions -* @return {number} x coordinate in camera space -*/ -Phaser.TilemapLayer.prototype._unfixX = function (x) { - - if (this.scrollFactorX === 1) - { - return x; - } - - return (this._scrollX / this.scrollFactorX) + (x - this._scrollX); - -}; - -/** -* Take a y coordinate that doesn't account for scrollFactorY and 'fix' it into a scrolled local space. -* -* @method Phaser.TilemapLayer#_fixY -* @private -* @param {number} y - y coordinate in camera space -* @return {number} y coordinate in scrollFactor-adjusted dimensions -*/ -Phaser.TilemapLayer.prototype._fixY = function (y) { - - if (this.scrollFactorY === 1 || (this.scrollFactorY === 0 && this.position.y === 0)) - { - return y; - } - - // This executes if the scrollFactorY is 0 and the y position of the tilemap is off from standard. - if (this.scrollFactorY === 0 && this.position.y !== 0) - { - return y - this.position.y; - } - - return this._scrollY + (y - (this._scrollY / this.scrollFactorY)); - -}; - -/** -* Take a y coordinate that _does_ account for scrollFactorY and 'unfix' it back to camera space. -* -* @method Phaser.TilemapLayer#_unfixY -* @private -* @param {number} y - y coordinate in scrollFactor-adjusted dimensions -* @return {number} y coordinate in camera space -*/ -Phaser.TilemapLayer.prototype._unfixY = function (y) { - - if (this.scrollFactorY === 1) - { - return y; - } - - return (this._scrollY / this.scrollFactorY) + (y - this._scrollY); - -}; - -/** -* Convert a pixel value to a tile coordinate. -* -* @method Phaser.TilemapLayer#getTileX -* @public -* @param {number} x - X position of the point in target tile (in pixels). -* @return {integer} The X map location of the tile. -*/ -Phaser.TilemapLayer.prototype.getTileX = function (x) { - - // var tileWidth = this.tileWidth * this.scale.x; - return Math.floor(this._fixX(x) / this._mc.tileWidth); - -}; - -/** -* Convert a pixel value to a tile coordinate. -* -* @method Phaser.TilemapLayer#getTileY -* @public -* @param {number} y - Y position of the point in target tile (in pixels). -* @return {integer} The Y map location of the tile. -*/ -Phaser.TilemapLayer.prototype.getTileY = function (y) { - - // var tileHeight = this.tileHeight * this.scale.y; - return Math.floor(this._fixY(y) / this._mc.tileHeight); - -}; - -/** -* Convert a pixel coordinate to a tile coordinate. -* -* @method Phaser.TilemapLayer#getTileXY -* @public -* @param {number} x - X position of the point in target tile (in pixels). -* @param {number} y - Y position of the point in target tile (in pixels). -* @param {(Phaser.Point|object)} point - The Point/object to update. -* @return {(Phaser.Point|object)} A Point/object with its `x` and `y` properties set. -*/ -Phaser.TilemapLayer.prototype.getTileXY = function (x, y, point) { - - point.x = this.getTileX(x); - point.y = this.getTileY(y); - - return point; - -}; - - /** * Returns the appropriate tileset for the index, updating the internal cache as required. * This should only be called if `tilesets[index]` evaluates to undefined. diff --git a/src/tilemap/TilemapLayerGL.js b/src/tilemap/TilemapLayerGL.js index 480f8d191..73d84d0c0 100644 --- a/src/tilemap/TilemapLayerGL.js +++ b/src/tilemap/TilemapLayerGL.js @@ -29,14 +29,6 @@ Phaser.TilemapLayerGL = function (game, tilemap, index, width, height, tileset) this.game = game; - /** - * The rendering offset. - * - * @property {Phaser.Point} _offset - * @private - */ - this._offset = new Phaser.Point(); - /** * An Array of any linked layers. * @@ -309,139 +301,6 @@ Phaser.TilemapLayerGL.prototype.resizeWorld = function () { }; -/** -* Take an x coordinate that doesn't account for scrollFactorX and 'fix' it into a scrolled local space. -* -* @method Phaser.TilemapLayerGL#_fixX -* @private -* @param {number} x - x coordinate in camera space -* @return {number} x coordinate in scrollFactor-adjusted dimensions -*/ -Phaser.TilemapLayerGL.prototype._fixX = function (x) { - - if (x < 0) - { - x = 0; - } - - if (this.scrollFactorX === 1) - { - return x; - } - - return this._scrollX + (x - (this._scrollX / this.scrollFactorX)); - -}; - -/** -* Take an x coordinate that _does_ account for scrollFactorX and 'unfix' it back to camera space. -* -* @method Phaser.TilemapLayerGL#_unfixX -* @private -* @param {number} x - x coordinate in scrollFactor-adjusted dimensions -* @return {number} x coordinate in camera space -*/ -Phaser.TilemapLayerGL.prototype._unfixX = function (x) { - - if (this.scrollFactorX === 1) - { - return x; - } - - return (this._scrollX / this.scrollFactorX) + (x - this._scrollX); - -}; - -/** -* Take a y coordinate that doesn't account for scrollFactorY and 'fix' it into a scrolled local space. -* -* @method Phaser.TilemapLayerGL#_fixY -* @private -* @param {number} y - y coordinate in camera space -* @return {number} y coordinate in scrollFactor-adjusted dimensions -*/ -Phaser.TilemapLayerGL.prototype._fixY = function (y) { - - if (y < 0) - { - y = 0; - } - - if (this.scrollFactorY === 1) - { - return y; - } - - return this._scrollY + (y - (this._scrollY / this.scrollFactorY)); - -}; - -/** -* Take a y coordinate that _does_ account for scrollFactorY and 'unfix' it back to camera space. -* -* @method Phaser.TilemapLayerGL#_unfixY -* @private -* @param {number} y - y coordinate in scrollFactor-adjusted dimensions -* @return {number} y coordinate in camera space -*/ -Phaser.TilemapLayerGL.prototype._unfixY = function (y) { - - if (this.scrollFactorY === 1) - { - return y; - } - - return (this._scrollY / this.scrollFactorY) + (y - this._scrollY); - -}; - -/** -* Convert a pixel value to a tile coordinate. -* -* @method Phaser.TilemapLayerGL#getTileX -* @public -* @param {number} x - X position of the point in target tile (in pixels). -* @return {integer} The X map location of the tile. -*/ -Phaser.TilemapLayerGL.prototype.getTileX = function (x) { - - return Math.floor(this._fixX(x) / this._mc.tileWidth); - -}; - -/** -* Convert a pixel value to a tile coordinate. -* -* @method Phaser.TilemapLayerGL#getTileY -* @public -* @param {number} y - Y position of the point in target tile (in pixels). -* @return {integer} The Y map location of the tile. -*/ -Phaser.TilemapLayerGL.prototype.getTileY = function (y) { - - return Math.floor(this._fixY(y) / this._mc.tileHeight); - -}; - -/** -* Convert a pixel coordinate to a tile coordinate. -* -* @method Phaser.TilemapLayerGL#getTileXY -* @public -* @param {number} x - X position of the point in target tile (in pixels). -* @param {number} y - Y position of the point in target tile (in pixels). -* @param {(Phaser.Point|object)} point - The Point/object to update. -* @return {(Phaser.Point|object)} A Point/object with its `x` and `y` properties set. -*/ -Phaser.TilemapLayerGL.prototype.getTileXY = function (x, y, point) { - - point.x = this.getTileX(x); - point.y = this.getTileY(y); - - return point; - -}; - /** * The TilemapLayerGL caches tileset look-ups. * @@ -668,17 +527,17 @@ Object.defineProperty(Phaser.TilemapLayerGL.prototype, "x", { get: function () { - return this._offset.x; + return this.position.x; }, set: function (value) { - this._offset.x = value; + this.position.x = value; for (var i = 0; i < this.linkedLayers.length; i++) { - this.linkedLayers[i]._offset.x = value; + this.linkedLayers[i].position.x = value; } this.dirty = true; @@ -691,17 +550,17 @@ Object.defineProperty(Phaser.TilemapLayerGL.prototype, "y", { get: function () { - return this._offset.y; + return this.position.y; }, set: function (value) { - this.offset.y = value; + this.position.y = value; for (var i = 0; i < this.linkedLayers.length; i++) { - this.linkedLayers[i]._offset.y = value; + this.linkedLayers[i].position.y = value; } this.dirty = true;