Math.between will return a value between the given min and max values.

This commit is contained in:
photonstorm 2016-06-03 16:18:35 +01:00
parent ee6f277b31
commit 93b1f3eba1
3 changed files with 16 additions and 0 deletions

View file

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

View file

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

View file

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