diff --git a/README.md b/README.md index 44f5f6d27..f7a36a4eb 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ Version 2.1.0 - "Cairhien" - -in development- * 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. * Phaser.Canvas.setImageRenderingCrisp now sets `image-rendering: pixelated`, perfect for pixel art, which is now supported in Chrome 38. * 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) +* Rectangle.centerOn(x,y) allows you to quickly center a Rectangle on the given coordinates. ### Updates diff --git a/src/geom/Rectangle.js b/src/geom/Rectangle.js index 59f4c3b68..d527c5e4b 100644 --- a/src/geom/Rectangle.js +++ b/src/geom/Rectangle.js @@ -94,6 +94,23 @@ Phaser.Rectangle.prototype = { }, + /** + * Centers this Rectangle so that the center coordinates match the given x and y values. + * + * @method Phaser.Rectangle#centerOn + * @param {number} x - The x coordinate to place the center of the Rectangle at. + * @param {number} y - The y coordinate to place the center of the Rectangle at. + * @return {Phaser.Rectangle} This Rectangle object + */ + centerOn: function (x, y) { + + this.centerX = x; + this.centerY = y; + + return this; + + }, + /** * Runs Math.floor() on both the x and y values of this Rectangle. * @method Phaser.Rectangle#floor