mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
New Frame Crop function.
This commit is contained in:
parent
4b42972a9b
commit
d34a5062c0
2 changed files with 60 additions and 4 deletions
|
@ -431,11 +431,17 @@ Phaser.Component.Transform.prototype = {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
w0 = frame.width * (1 - this._anchorX);
|
// w0 = frame.width * (1 - this._anchorX);
|
||||||
w1 = frame.width * -this._anchorX;
|
// w1 = frame.width * -this._anchorX;
|
||||||
|
|
||||||
h0 = frame.height * (1 - this._anchorY);
|
// h0 = frame.height * (1 - this._anchorY);
|
||||||
h1 = frame.height * -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;
|
var resolution = frame.source.resolution;
|
||||||
|
|
50
src/textures/Crop.js
Normal file
50
src/textures/Crop.js
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/**
|
||||||
|
* @author Richard Davey <rich@photonstorm.com>
|
||||||
|
* @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;
|
||||||
|
};
|
Loading…
Reference in a new issue