Phaser.Utils.Bounds functions.

This commit is contained in:
Richard Davey 2017-02-28 00:32:30 +00:00
parent 1f8702e323
commit c312d0ef8b
16 changed files with 256 additions and 0 deletions

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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')
};