2015-03-01 07:00:17 +00:00
|
|
|
/**
|
2015-03-23 23:27:14 +00:00
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2016-04-04 21:15:01 +00:00
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
2015-03-23 23:27:14 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The ScaleMinMax component allows a Game Object to limit how far it can be scaled by its parent.
|
2015-03-01 07:00:17 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
*/
|
2015-02-17 05:15:04 +00:00
|
|
|
Phaser.Component.ScaleMinMax = function () {};
|
|
|
|
|
|
|
|
Phaser.Component.ScaleMinMax.prototype = {
|
|
|
|
|
|
|
|
/**
|
2015-03-23 23:27:14 +00:00
|
|
|
* The callback that will apply any scale limiting to the worldTransform.
|
|
|
|
* @property {function} transformCallback
|
2015-02-17 05:15:04 +00:00
|
|
|
*/
|
2015-10-13 12:32:55 +00:00
|
|
|
transformCallback: null,
|
2015-02-17 05:15:04 +00:00
|
|
|
|
|
|
|
/**
|
2015-03-23 23:27:14 +00:00
|
|
|
* The context under which `transformCallback` is called.
|
|
|
|
* @property {object} transformCallbackContext
|
2015-02-17 05:15:04 +00:00
|
|
|
*/
|
|
|
|
transformCallbackContext: this,
|
|
|
|
|
|
|
|
/**
|
2015-03-23 23:27:14 +00:00
|
|
|
* The minimum scale this Game Object will scale down to.
|
|
|
|
*
|
|
|
|
* It allows you to prevent a parent from scaling this Game Object lower than the given value.
|
|
|
|
*
|
|
|
|
* Set it to `null` to remove the limit.
|
|
|
|
* @property {Phaser.Point} scaleMin
|
2015-02-17 05:15:04 +00:00
|
|
|
*/
|
|
|
|
scaleMin: null,
|
|
|
|
|
|
|
|
/**
|
2015-03-23 23:27:14 +00:00
|
|
|
* The maximum scale this Game Object will scale up to.
|
|
|
|
*
|
|
|
|
* It allows you to prevent a parent from scaling this Game Object higher than the given value.
|
|
|
|
*
|
|
|
|
* Set it to `null` to remove the limit.
|
|
|
|
* @property {Phaser.Point} scaleMax
|
2015-02-17 05:15:04 +00:00
|
|
|
*/
|
|
|
|
scaleMax: null,
|
|
|
|
|
|
|
|
/**
|
2015-03-23 23:27:14 +00:00
|
|
|
* Adjust scaling limits, if set, to this Game Object.
|
2015-02-17 05:15:04 +00:00
|
|
|
*
|
2015-03-01 07:00:17 +00:00
|
|
|
* @method
|
2015-02-17 05:15:04 +00:00
|
|
|
* @private
|
2016-10-07 02:34:42 +00:00
|
|
|
* @param {Phaser.Matrix} wt - The updated worldTransform matrix.
|
2015-02-17 05:15:04 +00:00
|
|
|
*/
|
|
|
|
checkTransform: function (wt) {
|
|
|
|
|
|
|
|
if (this.scaleMin)
|
|
|
|
{
|
|
|
|
if (wt.a < this.scaleMin.x)
|
|
|
|
{
|
|
|
|
wt.a = this.scaleMin.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wt.d < this.scaleMin.y)
|
|
|
|
{
|
|
|
|
wt.d = this.scaleMin.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.scaleMax)
|
|
|
|
{
|
|
|
|
if (wt.a > this.scaleMax.x)
|
|
|
|
{
|
|
|
|
wt.a = this.scaleMax.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wt.d > this.scaleMax.y)
|
|
|
|
{
|
|
|
|
wt.d = this.scaleMax.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-03-23 23:27:14 +00:00
|
|
|
* Sets the scaleMin and scaleMax values. These values are used to limit how far this Game Object will scale based on its parent.
|
|
|
|
*
|
|
|
|
* For example if this Game Object has a `minScale` value of 1 and its parent has a `scale` value of 0.5, the 0.5 will be ignored
|
|
|
|
* and the scale value of 1 will be used, as the parents scale is lower than the minimum scale this Game Object should adhere to.
|
|
|
|
*
|
|
|
|
* By setting these values you can carefully control how Game Objects deal with responsive scaling.
|
2015-02-17 05:15:04 +00:00
|
|
|
*
|
|
|
|
* If only one parameter is given then that value will be used for both scaleMin and scaleMax:
|
2015-03-23 23:27:14 +00:00
|
|
|
* `setScaleMinMax(1)` = scaleMin.x, scaleMin.y, scaleMax.x and scaleMax.y all = 1
|
2015-02-17 05:15:04 +00:00
|
|
|
*
|
|
|
|
* If only two parameters are given the first is set as scaleMin.x and y and the second as scaleMax.x and y:
|
2015-03-23 23:27:14 +00:00
|
|
|
* `setScaleMinMax(0.5, 2)` = scaleMin.x and y = 0.5 and scaleMax.x and y = 2
|
2015-02-17 05:15:04 +00:00
|
|
|
*
|
2015-03-23 23:27:14 +00:00
|
|
|
* If you wish to set `scaleMin` with different values for x and y then either modify Game Object.scaleMin directly,
|
|
|
|
* or pass `null` for the `maxX` and `maxY` parameters.
|
2015-02-17 05:15:04 +00:00
|
|
|
*
|
2015-03-23 23:27:14 +00:00
|
|
|
* Call `setScaleMinMax(null)` to clear all previously set values.
|
2015-02-17 05:15:04 +00:00
|
|
|
*
|
2015-03-01 07:00:17 +00:00
|
|
|
* @method
|
2015-03-23 23:27:14 +00:00
|
|
|
* @param {number|null} minX - The minimum horizontal scale value this Game Object can scale down to.
|
|
|
|
* @param {number|null} minY - The minimum vertical scale value this Game Object can scale down to.
|
|
|
|
* @param {number|null} maxX - The maximum horizontal scale value this Game Object can scale up to.
|
|
|
|
* @param {number|null} maxY - The maximum vertical scale value this Game Object can scale up to.
|
2015-02-17 05:15:04 +00:00
|
|
|
*/
|
|
|
|
setScaleMinMax: function (minX, minY, maxX, maxY) {
|
|
|
|
|
2015-07-22 09:37:15 +00:00
|
|
|
if (minY === undefined)
|
2015-02-17 05:15:04 +00:00
|
|
|
{
|
|
|
|
// 1 parameter, set all to it
|
|
|
|
minY = maxX = maxY = minX;
|
|
|
|
}
|
2015-07-22 09:37:15 +00:00
|
|
|
else if (maxX === undefined)
|
2015-02-17 05:15:04 +00:00
|
|
|
{
|
|
|
|
// 2 parameters, the first is min, the second max
|
|
|
|
maxX = maxY = minY;
|
|
|
|
minY = minX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (minX === null)
|
|
|
|
{
|
|
|
|
this.scaleMin = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (this.scaleMin)
|
|
|
|
{
|
|
|
|
this.scaleMin.set(minX, minY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.scaleMin = new Phaser.Point(minX, minY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxX === null)
|
|
|
|
{
|
|
|
|
this.scaleMax = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (this.scaleMax)
|
|
|
|
{
|
|
|
|
this.scaleMax.set(maxX, maxY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.scaleMax = new Phaser.Point(maxX, maxY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-13 12:32:55 +00:00
|
|
|
if (this.scaleMin === null)
|
|
|
|
{
|
|
|
|
this.transformCallback = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.transformCallback = this.checkTransform;
|
|
|
|
this.transformCallbackContext = this;
|
|
|
|
}
|
|
|
|
|
2015-02-17 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|