Skip to content

Commit cb14fd1

Browse files
committed
Rectangle.centerOn(x,y) allows you to quickly center a Rectangle on the given coordinates.
1 parent ac9c9a1 commit cb14fd1

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Version 2.1.0 - "Cairhien" - -in development-
107107
* RetroFont has a new property called frameData which contains the Frame objects for each of the letters in the font, which can be used by Sprites.
108108
* Phaser.Canvas.setImageRenderingCrisp now sets `image-rendering: pixelated`, perfect for pixel art, which is now supported in Chrome 38.
109109
* Phaser.Mouse will now add a listener to the `window` to detect `mouseup` events. This is used to detect if the player releases the mouse while outside of the game canvas. Previously Pointer objects incorrectly thought they were still pressed when you returned the mouse over the canvas (#1167)
110+
* Rectangle.centerOn(x,y) allows you to quickly center a Rectangle on the given coordinates.
110111

111112
### Updates
112113

src/geom/Rectangle.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ Phaser.Rectangle.prototype = {
9494

9595
},
9696

97+
/**
98+
* Centers this Rectangle so that the center coordinates match the given x and y values.
99+
*
100+
* @method Phaser.Rectangle#centerOn
101+
* @param {number} x - The x coordinate to place the center of the Rectangle at.
102+
* @param {number} y - The y coordinate to place the center of the Rectangle at.
103+
* @return {Phaser.Rectangle} This Rectangle object
104+
*/
105+
centerOn: function (x, y) {
106+
107+
this.centerX = x;
108+
this.centerY = y;
109+
110+
return this;
111+
112+
},
113+
97114
/**
98115
* Runs Math.floor() on both the x and y values of this Rectangle.
99116
* @method Phaser.Rectangle#floor

0 commit comments

Comments
 (0)