Skip to content

Commit 3c239ab

Browse files
committed
Add Display.Bounds.GetBounds()
1 parent d6e8600 commit 3c239ab

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

src/display/bounds/GetBounds.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @author samme
3+
* @copyright 2020 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
var GetBottom = require('./GetBottom');
8+
var GetLeft = require('./GetLeft');
9+
var GetRight = require('./GetRight');
10+
var GetTop = require('./GetTop');
11+
12+
/**
13+
* Returns the unrotated bounds of the Game Object as a rectangle.
14+
*
15+
* @function Phaser.Display.Bounds.GetBounds
16+
* @since 3.24.0
17+
*
18+
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to get the bounds value from.
19+
* @param {(Phaser.Geom.Rectangle|object)} [output] - An object to store the values in.
20+
*
21+
* @return {(Phaser.Geom.Rectangle|object)} - The bounds of the Game Object.
22+
*/
23+
var GetBounds = function (gameObject, output)
24+
{
25+
if (output === undefined) { output = {}; }
26+
27+
var left = GetLeft(gameObject);
28+
var top = GetTop(gameObject);
29+
30+
output.x = left;
31+
output.y = top;
32+
output.width = GetRight(gameObject) - left;
33+
output.height = GetBottom(gameObject) - top;
34+
35+
return output;
36+
};
37+
38+
module.exports = GetBounds;

src/display/bounds/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212

1313
CenterOn: require('./CenterOn'),
1414
GetBottom: require('./GetBottom'),
15+
GetBounds: require('./GetBounds'),
1516
GetCenterX: require('./GetCenterX'),
1617
GetCenterY: require('./GetCenterY'),
1718
GetLeft: require('./GetLeft'),
@@ -25,5 +26,5 @@ module.exports = {
2526
SetLeft: require('./SetLeft'),
2627
SetRight: require('./SetRight'),
2728
SetTop: require('./SetTop')
28-
29+
2930
};

0 commit comments

Comments
 (0)