phaser/src/gameobjects/components/Bounds.js

121 lines
2.1 KiB
JavaScript
Raw Normal View History

/**
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 Bounds component contains properties related to the bounds of the Game Object.
*
* @class
*/
Phaser.Component.Bounds = function () {};
Phaser.Component.Bounds.prototype = {
/**
2015-03-23 23:27:14 +00:00
* 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.
*
2015-03-23 23:27:14 +00:00
* @property {number} offsetX
* @readOnly
*/
offsetX: {
get: function () {
return this.anchor.x * this.width;
}
},
/**
2015-03-23 23:27:14 +00:00
* The amount the Game Object is visually offset from its y coordinate.
* This is the same as `height * anchor.y`.
* It will only be > 0 if anchor.y is not equal to zero.
*
2015-03-23 23:27:14 +00:00
* @property {number} offsetY
* @readOnly
*/
offsetY: {
get: function () {
return this.anchor.y * this.height;
}
},
/**
2015-03-23 23:27:14 +00:00
* The left coordinate of the Game Object.
* This is the same as `x - offsetX`.
*
2015-03-23 23:27:14 +00:00
* @property {number} left
* @readOnly
*/
left: {
get: function () {
return this.x - this.offsetX;
}
},
/**
2015-03-23 23:27:14 +00:00
* The right coordinate of the Game Object.
* This is the same as `x + width - offsetX`.
*
2015-03-23 23:27:14 +00:00
* @property {number} right
* @readOnly
*/
right: {
get: function () {
return (this.x + this.width) - this.offsetX;
}
},
/**
2015-03-23 23:27:14 +00:00
* The y coordinate of the Game Object.
* This is the same as `y - offsetY`.
*
2015-03-23 23:27:14 +00:00
* @property {number} top
* @readOnly
*/
top: {
get: function () {
return this.y - this.offsetY;
}
},
/**
2015-03-23 23:27:14 +00:00
* The sum of the y and height properties.
* This is the same as `y + height - offsetY`.
*
2015-03-23 23:27:14 +00:00
* @property {number} bottom
* @readOnly
*/
bottom: {
get: function () {
return (this.y + this.height) - this.offsetY;
}
}
};