Rectangle.centerOn(x,y) allows you to quickly center a Rectangle on the given coordinates.

This commit is contained in:
photonstorm 2014-09-05 04:13:21 +01:00
parent ac9c9a1f9b
commit cb14fd1c01
2 changed files with 18 additions and 0 deletions

View file

@ -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

View file

@ -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