Skip to content

Commit 93b1f3e

Browse files
committed
Math.between will return a value between the given min and max values.
1 parent ee6f277 commit 93b1f3e

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
345345
* 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.
346346
* 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)
347347
* 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`.
348+
* Math.between will return a value between the given `min` and `max` values.
348349

349350
### Updates
350351

src/math/Math.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ Phaser.Math = {
2323
*/
2424
PI2: Math.PI * 2,
2525

26+
/**
27+
* Returns a number between the `min` and `max` values.
28+
*
29+
* @method Phaser.Math#between
30+
* @param {number} min - The minimum value. Must be positive, and less than 'max'.
31+
* @param {number} max - The maximum value. Must be position, and greater than 'min'.
32+
* @return {number} A value between the range min to max.
33+
*/
34+
between: function (min, max) {
35+
36+
return Math.floor(Math.random() * (max - min + 1) + min);
37+
38+
},
39+
2640
/**
2741
* Two number are fuzzyEqual if their difference is less than epsilon.
2842
*

typescript/phaser.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,6 +2480,7 @@ declare module "phaser" {
24802480
static angleBetweenPointsY(point1: Phaser.Point, point2: Phaser.Point): number;
24812481
static average(...numbers: number[]): number;
24822482
static bernstein(n: number, i: number): number;
2483+
static between(min: number, max: number): number;
24832484
static bezierInterpolation(v: number[], k: number): number;
24842485
static catmullRom(p0: number, p1: number, p2: number, p3: number, t: number): number;
24852486
static catmullRomInterpolation(v: number[], k: number): number;

0 commit comments

Comments
 (0)