Skip to content

Commit 30972f4

Browse files
committed
Camera.getBounds is a new method that will return a rectangle containing the bounds of the camera.
1 parent 052da6e commit 30972f4

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
* `Geom.Intersects.PointToLine` has a new optional argument `lineThickness` (which defaults to 1). This allows you to determine if the point intersects a line of a given thickness, where the line-ends are circular (not square).
6363
* `Geom.Line.GetNearestPoint` is a new static method that will return the nearest point on a line to the given point.
6464
* `Geom.Line.GetShortestDistance` is a new static method that will return the shortest distance from a line to the given point.
65+
* `Camera.getBounds` is a new method that will return a rectangle containing the bounds of the camera.
6566

6667
### Updates
6768

src/cameras/2d/BaseCamera.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,12 +1079,14 @@ var BaseCamera = new Class({
10791079
* @param {integer} y - The top-left y coordinate of the bounds.
10801080
* @param {integer} width - The width of the bounds, in pixels.
10811081
* @param {integer} height - The height of the bounds, in pixels.
1082-
* @param {boolean} [centerOn] - If `true` the Camera will automatically be centered on the new bounds.
1082+
* @param {boolean} [centerOn=false] - If `true` the Camera will automatically be centered on the new bounds.
10831083
*
10841084
* @return {Phaser.Cameras.Scene2D.BaseCamera} This Camera instance.
10851085
*/
10861086
setBounds: function (x, y, width, height, centerOn)
10871087
{
1088+
if (centerOn === undefined) { centerOn = false; }
1089+
10881090
this._bounds.setTo(x, y, width, height);
10891091

10901092
this.dirty = true;
@@ -1103,6 +1105,31 @@ var BaseCamera = new Class({
11031105
return this;
11041106
},
11051107

1108+
/**
1109+
* Returns a rectangle containing the bounds of the Camera.
1110+
*
1111+
* If the Camera does not have any bounds the rectangle will be empty.
1112+
*
1113+
* The rectangle is a copy of the bounds, so is safe to modify.
1114+
*
1115+
* @method Phaser.Cameras.Scene2D.BaseCamera#getBounds
1116+
* @since 3.16.0
1117+
*
1118+
* @param {Phaser.Geom.Rectangle} [out] - An optional Rectangle to store the bounds in. If not given, a new Rectangle will be created.
1119+
*
1120+
* @return {Phaser.Geom.Rectangle} A rectangle containing the bounds of this Camera.
1121+
*/
1122+
getBounds: function (out)
1123+
{
1124+
if (out === undefined) { out = new Rectangle(); }
1125+
1126+
var source = this._bounds;
1127+
1128+
out.setTo(source.x, source.y, source.width, source.height);
1129+
1130+
return out;
1131+
},
1132+
11061133
/**
11071134
* Sets the name of this Camera.
11081135
* This value is for your own use and isn't used internally.

0 commit comments

Comments
 (0)