diff --git a/README.md b/README.md index 181dfe2c1..d0e75413c 100644 --- a/README.md +++ b/README.md @@ -345,6 +345,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/ * Game Objects including Sprite, Image, Particle, TilemapLayer, Text, BitmapText and TileSprite have a new property called `data`. This is an empty Object that Phaser will never touch internally, but your own code, or Phaser Plugins, can store Game Object specific data within it. This allows you to associate data with a Game Object without having to pollute or change its class shape. * TilemapLayers will now collide properly when they have a position that isn't set to 0x0. For example if you're stitching together several maps, one after the other, and manually adjust their `scrollX/Y` properties (thanks @Upperfoot #2522) * There are a bunch of new Phaser consts available to help with setting the angle of a Game Object. They are `Phaser.ANGLE_UP`, `ANGLE_DOWN`, `ANGLE_LEFT`, `ANGLE_RIGHT`, `ANGLE_NORTH_EAST`, `ANGLE_NORTH_WEST`, `ANGLE_SOUTH_EAST` and `ANGLE_SOUTH_WEST`. +* Math.between will return a value between the given `min` and `max` values. ### Updates diff --git a/src/math/Math.js b/src/math/Math.js index dc0760c01..e55901917 100644 --- a/src/math/Math.js +++ b/src/math/Math.js @@ -23,6 +23,20 @@ Phaser.Math = { */ PI2: Math.PI * 2, + /** + * Returns a number between the `min` and `max` values. + * + * @method Phaser.Math#between + * @param {number} min - The minimum value. Must be positive, and less than 'max'. + * @param {number} max - The maximum value. Must be position, and greater than 'min'. + * @return {number} A value between the range min to max. + */ + between: function (min, max) { + + return Math.floor(Math.random() * (max - min + 1) + min); + + }, + /** * Two number are fuzzyEqual if their difference is less than epsilon. * diff --git a/typescript/phaser.d.ts b/typescript/phaser.d.ts index 28b912387..a698e787e 100644 --- a/typescript/phaser.d.ts +++ b/typescript/phaser.d.ts @@ -2480,6 +2480,7 @@ declare module "phaser" { static angleBetweenPointsY(point1: Phaser.Point, point2: Phaser.Point): number; static average(...numbers: number[]): number; static bernstein(n: number, i: number): number; + static between(min: number, max: number): number; static bezierInterpolation(v: number[], k: number): number; static catmullRom(p0: number, p1: number, p2: number, p3: number, t: number): number; static catmullRomInterpolation(v: number[], k: number): number;