mirror of
https://github.com/photonstorm/phaser
synced 2024-11-10 15:14:47 +00:00
Math.getNextPowerOfTwo will get the next power of two for the given value.
Math.isPowerOfTwo will return a boolean if the given width and height are a power of two.
This commit is contained in:
parent
bffdb8fbc5
commit
eda4961c06
3 changed files with 50 additions and 0 deletions
|
@ -338,6 +338,10 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
|
|||
* PIXI.TilingSprite has been removed, and all functionality merged in to Phaser.TileSprite, to cut down on the number of internal classes and inheritance going on.
|
||||
* PIXI.CanvasPool has been moved into the Phaser `utils` folder, and renamed to `Phaser.CanvasPool`. All references to PIXI.CanvasPool have been updated to match the new namespace.
|
||||
* PIXI.EarCut has been moved into the Phaser `utils` folder, and renamed to `Phaser.EarCut`. All references to PIXI.EarCut have been updated to match the new namespace.
|
||||
* Device.canHandleAlpha is a new boolean property that stores is the browser is capable of tinting with alpha.
|
||||
* Device.canUseMultiply is a new boolean property that stores whether or not the Canvas BlendModes are supported, consequently the ability to tint using the multiply method.
|
||||
* Math.getNextPowerOfTwo will get the next power of two for the given value.
|
||||
* Math.isPowerOfTwo will return a boolean if the given width and height are a power of two.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
|
@ -360,6 +364,7 @@ Please note that Phaser uses a custom build of Pixi and always has done. The fol
|
|||
* PIXI.RenderTexture has been removed as it's no longer used internally.
|
||||
* PIXI.TileSprite has been removed as it's no longer used internally.
|
||||
* PIXI.EarCut has been removed as it's no longer used internally.
|
||||
* PIXI.Utils has been removed. All functionality is now available in Phaser.
|
||||
|
||||
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).
|
||||
|
||||
|
|
|
@ -23,6 +23,49 @@ Phaser.Math = {
|
|||
*/
|
||||
PI2: Math.PI * 2,
|
||||
|
||||
/**
|
||||
* Given a number, this function returns the closest number that is a power of two.
|
||||
* This function is from the Starling Framework.
|
||||
*
|
||||
* @method Phaser.Math#getNextPowerOfTwo
|
||||
* @param {number} value - The value to get the closest power of two from.
|
||||
* @return {number} The closest number that is a power of two.
|
||||
*/
|
||||
getNextPowerOfTwo: function (value) {
|
||||
|
||||
if (value > 0 && (value & (value - 1)) === 0)
|
||||
{
|
||||
// http://goo.gl/D9kPj
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = 1;
|
||||
|
||||
while (result < value)
|
||||
{
|
||||
result <<= 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given dimensions make a power of two texture.
|
||||
*
|
||||
* @method Phaser.Math#isPowerOfTwo
|
||||
* @param {number} width - The width to check.
|
||||
* @param {number} height - The height to check.
|
||||
* @return {boolean} True if the width and height are a power of two.
|
||||
*/
|
||||
isPowerOfTwo: function (width, height) {
|
||||
|
||||
return (width > 0 && (width & (width - 1)) === 0 && height > 0 && (height & (height - 1)) === 0);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a random float in the range `[min, max)`. If these parameters are not in order than they will be put in order.
|
||||
* Default is 0 for `min` and 1 for `max`.
|
||||
|
|
2
typescript/phaser.d.ts
vendored
2
typescript/phaser.d.ts
vendored
|
@ -2590,8 +2590,10 @@ declare module Phaser {
|
|||
static fuzzyGreaterThan(a: number, b: number, epsilon?: number): boolean;
|
||||
static fuzzyLessThan(a: number, b: number, epsilon?: number): boolean;
|
||||
static getShortestAngle(angle1: number, angle2: number): number;
|
||||
static getNextPowerOfTwo(value: number): number;
|
||||
static isEven(n: number): boolean;
|
||||
static isOdd(n: number): boolean;
|
||||
static isPowerOfTwo(width: number, height: number): boolean;
|
||||
static linear(p0: number, p1: number, t: number): number;
|
||||
static linearInterpolation(v: number[], k: number): number;
|
||||
static mapLinear(x: number, a1: number, a2: number, b1: number, b2: number): number;
|
||||
|
|
Loading…
Reference in a new issue