Rectangle.randomX will return a random value located within the horizontal bounds of the Rectangle.

Rectangle.randomY will return a random value located within the vertical bounds of the Rectangle.
This commit is contained in:
photonstorm 2014-07-09 11:34:18 +01:00
parent 003403c832
commit 494c33a9f4
3 changed files with 36 additions and 0 deletions

View file

@ -134,6 +134,8 @@ Version 2.0.6 - "Jornhill" - -in development-
* Phaser.Utils.mixin will mix the source object into the destination object, returning the newly modified destination object.
* You can now use `game.add.plugin` from the GameObjectFactory (thanks @alvinsight, #978)
* Color.getWebRGB will now accept either an Object or numeric color value.
* Rectangle.randomX will return a random value located within the horizontal bounds of the Rectangle.
* Rectangle.randomY will return a random value located within the vertical bounds of the Rectangle.
### Bug Fixes

2
build/phaser.d.ts vendored
View file

@ -4104,6 +4104,8 @@ declare module Phaser {
height: number;
left: number;
perimeter: number;
randomX: number;
randomY: number;
right: number;
top: number;
topLeft: Phaser.Point;

View file

@ -463,6 +463,38 @@ Object.defineProperty(Phaser.Rectangle.prototype, "centerY", {
});
/**
* A random value between the left and right values (inclusive) of the Rectangle.
*
* @name Phaser.Rectangle#randomX
* @property {number} randomX - A random value between the left and right values (inclusive) of the Rectangle.
*/
Object.defineProperty(Phaser.Rectangle.prototype, "randomX", {
get: function () {
return this.x + (Math.random() * this.width);
}
});
/**
* A random value between the top and bottom values (inclusive) of the Rectangle.
*
* @name Phaser.Rectangle#randomY
* @property {number} randomY - A random value between the top and bottom values (inclusive) of the Rectangle.
*/
Object.defineProperty(Phaser.Rectangle.prototype, "randomY", {
get: function () {
return this.y + (Math.random() * this.height);
}
});
/**
* The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
* However it does affect the height property, whereas changing the y value does not affect the height property.