diff --git a/src/components/Transform.js b/src/components/Transform.js index 9471c20f4..cd03a46fb 100644 --- a/src/components/Transform.js +++ b/src/components/Transform.js @@ -431,11 +431,17 @@ Phaser.Component.Transform.prototype = { } else { - w0 = frame.width * (1 - this._anchorX); - w1 = frame.width * -this._anchorX; + // w0 = frame.width * (1 - this._anchorX); + // w1 = frame.width * -this._anchorX; - h0 = frame.height * (1 - this._anchorY); - h1 = frame.height * -this._anchorY; + // h0 = frame.height * (1 - this._anchorY); + // h1 = frame.height * -this._anchorY; + + w0 = frame.cutWidth * (1 - this._anchorX); + w1 = frame.cutWidth * -this._anchorX; + + h0 = frame.cutHeight * (1 - this._anchorY); + h1 = frame.cutHeight * -this._anchorY; } var resolution = frame.source.resolution; diff --git a/src/textures/Crop.js b/src/textures/Crop.js new file mode 100644 index 000000000..b13e463b8 --- /dev/null +++ b/src/textures/Crop.js @@ -0,0 +1,50 @@ +/** +* @author Richard Davey +* @copyright 2016 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +*/ + +/** +* +* @class Phaser.TextureCrop +* @constructor +* @param {object} source +* @param {number} scaleMode +*/ +Phaser.TextureCrop = function (gameObject, width, height, x, y) +{ + var frame = gameObject.frame; + + if (width === undefined) { width = frame.data.cut.w; } + if (height === undefined) { height = frame.data.cut.h; } + if (x === undefined) { x = 0; } + if (y === undefined) { y = 0; } + + if (width === undefined) + { + // No arguments means reset the crop + frame.cutX = frame.data.cut.x; + frame.cutY = frame.data.cut.y; + frame.cutWidth = frame.data.cut.w; + frame.cutHeight = frame.data.cut.h; + } + else if (width !== frame.cutWidth || height !== frame.cutHeight || x !== frame.cutX || y !== frame.cutY) + { + frame.cutX = Phaser.Math.clamp(x, frame.data.cut.x, frame.data.cut.r); + frame.cutY = Phaser.Math.clamp(y, frame.data.cut.y, frame.data.cut.b); + frame.cutWidth = Phaser.Math.clamp(width, 0, frame.data.cut.w - frame.cutX); + frame.cutHeight = Phaser.Math.clamp(height, 0, frame.data.cut.h - frame.cutY); + } + + // ? + // frame.x = frame.cutX; + // frame.y = frame.cutY; + // frame.width = frame.cutWidth; + // frame.height = frame.cutHeight; + + frame.updateUVs(); + + gameObject.transform.updateVertexData(); + + return gameObject; +};