mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 14:38:30 +00:00
Phaser.Utils.Bounds functions.
This commit is contained in:
parent
1f8702e323
commit
c312d0ef8b
16 changed files with 256 additions and 0 deletions
23
v3/src/utils/bounds/CenterOn.js
Normal file
23
v3/src/utils/bounds/CenterOn.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
var CenterX = require('./CenterX');
|
||||
var CenterY = require('./CenterY');
|
||||
|
||||
/**
|
||||
* The center x coordinate of the Game Object.
|
||||
* This is the same as `(x - offsetX) + (width / 2)`.
|
||||
*
|
||||
* @property {number} centerX
|
||||
*/
|
||||
|
||||
// Phaser.Utils.Bounds.GetCenterX(bob)
|
||||
// Phaser.Utils.Bounds.CenterOn(bob, x, y)
|
||||
// Phaser.Utils.Bounds.CenterX(bob, x)
|
||||
// Phaser.Utils.Bounds.CenterY(bob, x)
|
||||
|
||||
var CenterOn = function (gameObject, x, y)
|
||||
{
|
||||
CenterX(gameObject, x);
|
||||
|
||||
return CenterY(gameObject, y);
|
||||
};
|
||||
|
||||
module.exports = CenterOn;
|
13
v3/src/utils/bounds/GetBottom.js
Normal file
13
v3/src/utils/bounds/GetBottom.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* The left coordinate of the Game Object.
|
||||
* This is the same as `x - offsetX`.
|
||||
*
|
||||
* @property {number} left
|
||||
*/
|
||||
|
||||
var GetBottom = function (gameObject)
|
||||
{
|
||||
return (gameObject.y + gameObject.height) - (gameObject.height * gameObject.anchorY);
|
||||
};
|
||||
|
||||
module.exports = GetBottom;
|
13
v3/src/utils/bounds/GetCenterX.js
Normal file
13
v3/src/utils/bounds/GetCenterX.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* The center x coordinate of the Game Object.
|
||||
* This is the same as `(x - offsetX) + (width / 2)`.
|
||||
*
|
||||
* @property {number} centerX
|
||||
*/
|
||||
|
||||
var GetCenterX = function (gameObject)
|
||||
{
|
||||
return gameObject.x - (gameObject.width * gameObject.anchorX) + (gameObject.width * 0.5);
|
||||
};
|
||||
|
||||
module.exports = GetCenterX;
|
13
v3/src/utils/bounds/GetCenterY.js
Normal file
13
v3/src/utils/bounds/GetCenterY.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* The center x coordinate of the Game Object.
|
||||
* This is the same as `(x - offsetX) + (width / 2)`.
|
||||
*
|
||||
* @property {number} centerX
|
||||
*/
|
||||
|
||||
var GetCenterY = function (gameObject)
|
||||
{
|
||||
return gameObject.y - (gameObject.height * gameObject.anchorY) + (gameObject.height * 0.5);
|
||||
};
|
||||
|
||||
module.exports = GetCenterY;
|
13
v3/src/utils/bounds/GetLeft.js
Normal file
13
v3/src/utils/bounds/GetLeft.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* The left coordinate of the Game Object.
|
||||
* This is the same as `x - offsetX`.
|
||||
*
|
||||
* @property {number} left
|
||||
*/
|
||||
|
||||
var GetLeft = function (gameObject)
|
||||
{
|
||||
return gameObject.x - (gameObject.width * gameObject.anchorX);
|
||||
};
|
||||
|
||||
module.exports = GetLeft;
|
15
v3/src/utils/bounds/GetOffsetX.js
Normal file
15
v3/src/utils/bounds/GetOffsetX.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* The amount the Game Object is visually offset from its x coordinate.
|
||||
* This is the same as `width * anchor.x`.
|
||||
* It will only be > 0 if anchor.x is not equal to zero.
|
||||
*
|
||||
* @property {number} offsetX
|
||||
* @readOnly
|
||||
*/
|
||||
|
||||
var GetOffsetX = function (gameObject)
|
||||
{
|
||||
return gameObject.width * gameObject.anchorX;
|
||||
};
|
||||
|
||||
module.exports = GetOffsetX;
|
15
v3/src/utils/bounds/GetOffsetY.js
Normal file
15
v3/src/utils/bounds/GetOffsetY.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* The amount the Game Object is visually offset from its x coordinate.
|
||||
* This is the same as `width * anchor.x`.
|
||||
* It will only be > 0 if anchor.x is not equal to zero.
|
||||
*
|
||||
* @property {number} offsetX
|
||||
* @readOnly
|
||||
*/
|
||||
|
||||
var GetOffsetY = function (gameObject)
|
||||
{
|
||||
return gameObject.height * gameObject.anchorY;
|
||||
};
|
||||
|
||||
module.exports = GetOffsetY;
|
13
v3/src/utils/bounds/GetRight.js
Normal file
13
v3/src/utils/bounds/GetRight.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* The left coordinate of the Game Object.
|
||||
* This is the same as `x - offsetX`.
|
||||
*
|
||||
* @property {number} left
|
||||
*/
|
||||
|
||||
var GetRight = function (gameObject)
|
||||
{
|
||||
return (gameObject.x + gameObject.width) - (gameObject.width * gameObject.anchorX);
|
||||
};
|
||||
|
||||
module.exports = GetRight;
|
13
v3/src/utils/bounds/GetTop.js
Normal file
13
v3/src/utils/bounds/GetTop.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* The y coordinate of the Game Object.
|
||||
* This is the same as `y - offsetY`.
|
||||
*
|
||||
* @property {number} top
|
||||
*/
|
||||
|
||||
var GetTop = function (gameObject)
|
||||
{
|
||||
return gameObject.y - (gameObject.height * gameObject.anchorY);
|
||||
};
|
||||
|
||||
module.exports = GetTop;
|
15
v3/src/utils/bounds/SetBottom.js
Normal file
15
v3/src/utils/bounds/SetBottom.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* The left coordinate of the Game Object.
|
||||
* This is the same as `x - offsetX`.
|
||||
*
|
||||
* @property {number} left
|
||||
*/
|
||||
|
||||
var SetBottom = function (gameObject, value)
|
||||
{
|
||||
gameObject.y = (value - gameObject.height) + (gameObject.height * gameObject.anchorY);
|
||||
|
||||
return gameObject;
|
||||
};
|
||||
|
||||
module.exports = SetBottom;
|
22
v3/src/utils/bounds/SetCenterX.js
Normal file
22
v3/src/utils/bounds/SetCenterX.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* The center x coordinate of the Game Object.
|
||||
* This is the same as `(x - offsetX) + (width / 2)`.
|
||||
*
|
||||
* @property {number} centerX
|
||||
*/
|
||||
|
||||
// Phaser.Utils.Bounds.GetCenterX(bob)
|
||||
// Phaser.Utils.Bounds.CenterOn(bob, x, y)
|
||||
// Phaser.Utils.Bounds.CenterX(bob, x)
|
||||
// Phaser.Utils.Bounds.CenterY(bob, x)
|
||||
|
||||
var SetCenterX = function (gameObject, x)
|
||||
{
|
||||
var offsetX = gameObject.width * gameObject.anchorX;
|
||||
|
||||
gameObject.x = (x + offsetX) - (gameObject.width * 0.5);
|
||||
|
||||
return gameObject;
|
||||
};
|
||||
|
||||
module.exports = SetCenterX;
|
22
v3/src/utils/bounds/SetCenterY.js
Normal file
22
v3/src/utils/bounds/SetCenterY.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* The center x coordinate of the Game Object.
|
||||
* This is the same as `(x - offsetX) + (width / 2)`.
|
||||
*
|
||||
* @property {number} centerX
|
||||
*/
|
||||
|
||||
// Phaser.Utils.Bounds.GetCenterX(bob)
|
||||
// Phaser.Utils.Bounds.CenterOn(bob, x, y)
|
||||
// Phaser.Utils.Bounds.CenterX(bob, x)
|
||||
// Phaser.Utils.Bounds.CenterY(bob, x)
|
||||
|
||||
var SetCenterY = function (gameObject, y)
|
||||
{
|
||||
var offsetY = gameObject.height * gameObject.anchorY;
|
||||
|
||||
gameObject.y = (y + offsetY) - (gameObject.height * 0.5);
|
||||
|
||||
return gameObject;
|
||||
};
|
||||
|
||||
module.exports = SetCenterY;
|
15
v3/src/utils/bounds/SetLeft.js
Normal file
15
v3/src/utils/bounds/SetLeft.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* The left coordinate of the Game Object.
|
||||
* This is the same as `x - offsetX`.
|
||||
*
|
||||
* @property {number} left
|
||||
*/
|
||||
|
||||
var SetLeft = function (gameObject, value)
|
||||
{
|
||||
gameObject.x = value + (gameObject.width * gameObject.anchorX);
|
||||
|
||||
return gameObject;
|
||||
};
|
||||
|
||||
module.exports = SetLeft;
|
15
v3/src/utils/bounds/SetRight.js
Normal file
15
v3/src/utils/bounds/SetRight.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* The left coordinate of the Game Object.
|
||||
* This is the same as `x - offsetX`.
|
||||
*
|
||||
* @property {number} left
|
||||
*/
|
||||
|
||||
var SetRight = function (gameObject, value)
|
||||
{
|
||||
gameObject.x = (value - gameObject.width) + (gameObject.width * gameObject.anchorX);
|
||||
|
||||
return gameObject;
|
||||
};
|
||||
|
||||
module.exports = SetRight;
|
15
v3/src/utils/bounds/SetTop.js
Normal file
15
v3/src/utils/bounds/SetTop.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* The y coordinate of the Game Object.
|
||||
* This is the same as `y - offsetY`.
|
||||
*
|
||||
* @property {number} top
|
||||
*/
|
||||
|
||||
var SetTop = function (gameObject, value)
|
||||
{
|
||||
gameObject.y = value + (gameObject.height * gameObject.anchorY);
|
||||
|
||||
return gameObject;
|
||||
};
|
||||
|
||||
module.exports = SetTop;
|
21
v3/src/utils/bounds/index.js
Normal file
21
v3/src/utils/bounds/index.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Phaser.Utils.Bounds
|
||||
|
||||
module.exports = {
|
||||
|
||||
CenterOn: require('./CenterOn'),
|
||||
GetBottom: require('./GetBottom'),
|
||||
GetCenterX: require('./GetCenterX'),
|
||||
GetCenterY: require('./GetCenterY'),
|
||||
GetLeft: require('./GetLeft'),
|
||||
GetOffsetX: require('./GetOffsetX'),
|
||||
GetOffsetY: require('./GetOffsetY'),
|
||||
GetRight: require('./GetRight'),
|
||||
GetTop: require('./GetTop'),
|
||||
SetBottom: require('./SetBottom'),
|
||||
SetCenterX: require('./SetCenterX'),
|
||||
SetCenterY: require('./SetCenterY'),
|
||||
SetLeft: require('./SetLeft'),
|
||||
SetRight: require('./SetRight'),
|
||||
SetTop: require('./SetTop')
|
||||
|
||||
};
|
Loading…
Add table
Reference in a new issue