mirror of
https://github.com/wassname/phaser.git
synced 2026-08-12 12:20:38 +08:00
Input, Loader and Math docs tidied up.
This commit is contained in:
+118
-85
@@ -2,7 +2,6 @@
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.Math
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -14,14 +13,13 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* = 2 π
|
||||
* @method PI2
|
||||
*
|
||||
* @method Phaser.Math#PI2
|
||||
*/
|
||||
PI2: Math.PI * 2,
|
||||
|
||||
/**
|
||||
* Two number are fuzzyEqual if their difference is less than ε.
|
||||
* @method fuzzyEqual
|
||||
* @method Phaser.Math#fuzzyEqual
|
||||
* @param {number} a
|
||||
* @param {number} b
|
||||
* @param {number} epsilon
|
||||
@@ -34,7 +32,7 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* a is fuzzyLessThan b if it is less than b + ε.
|
||||
* @method fuzzyEqual
|
||||
* @method Phaser.Math#fuzzyEqual
|
||||
* @param {number} a
|
||||
* @param {number} b
|
||||
* @param {number} epsilon
|
||||
@@ -47,7 +45,7 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* a is fuzzyGreaterThan b if it is more than b - ε.
|
||||
* @method fuzzyGreaterThan
|
||||
* @method Phaser.Math#fuzzyGreaterThan
|
||||
* @param {number} a
|
||||
* @param {number} b
|
||||
* @param {number} epsilon
|
||||
@@ -59,7 +57,7 @@ Phaser.Math = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @method fuzzyCeil
|
||||
* @method Phaser.Math#fuzzyCeil
|
||||
* @param {number} val
|
||||
* @param {number} epsilon
|
||||
* @return {boolean} ceiling(val-ε)
|
||||
@@ -70,7 +68,7 @@ Phaser.Math = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @method fuzzyFloor
|
||||
* @method Phaser.Math#fuzzyFloor
|
||||
* @param {number} val
|
||||
* @param {number} epsilon
|
||||
* @return {boolean} floor(val-ε)
|
||||
@@ -81,7 +79,9 @@ Phaser.Math = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @method average
|
||||
* Averages all values passed to the function and returns the result. You can pass as many parameters as you like.
|
||||
* @method Phaser.Math#average
|
||||
* @return {number} The average of all given values.
|
||||
*/
|
||||
average: function () {
|
||||
|
||||
@@ -102,16 +102,18 @@ Phaser.Math = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @method truncate
|
||||
* @method Phaser.Math#truncate
|
||||
* @param {number} n
|
||||
* @return {number}
|
||||
*/
|
||||
truncate: function (n) {
|
||||
return (n > 0) ? Math.floor(n) : Math.ceil(n);
|
||||
},
|
||||
|
||||
/**
|
||||
* @method shear
|
||||
* @param n
|
||||
* @return n mod 1
|
||||
* @method Phaser.Math#shear
|
||||
* @param {number} n
|
||||
* @return {number} n mod 1
|
||||
*/
|
||||
shear: function (n) {
|
||||
return n % 1;
|
||||
@@ -122,10 +124,11 @@ Phaser.Math = {
|
||||
*
|
||||
* Example: if you have an interval gap of 5 and a position of 12... you will snap to 10 whereas 14 will snap to 15.
|
||||
*
|
||||
* @method snapTo
|
||||
* @method Phaser.Math#snapTo
|
||||
* @param {number} input - The value to snap.
|
||||
* @param {number} gap - The interval gap of the grid.
|
||||
* @param {number} [start] - Optional starting offset for gap.
|
||||
* @return {number}
|
||||
*/
|
||||
snapTo: function (input, gap, start) {
|
||||
|
||||
@@ -147,10 +150,11 @@ Phaser.Math = {
|
||||
*
|
||||
* Example: if you have an interval gap of 5 and a position of 12... you will snap to 10. As will 14 snap to 10... but 16 will snap to 15
|
||||
*
|
||||
* @method snapToFloor
|
||||
* @method Phaser.Math#snapToFloor
|
||||
* @param {number} input - The value to snap.
|
||||
* @param {number} gap - The interval gap of the grid.
|
||||
* @param {number} [start] - Optional starting offset for gap.
|
||||
* @return {number}
|
||||
*/
|
||||
snapToFloor: function (input, gap, start) {
|
||||
|
||||
@@ -172,10 +176,11 @@ Phaser.Math = {
|
||||
*
|
||||
* Example: if you have an interval gap of 5 and a position of 12... you will snap to 15. As will 14 will snap to 15... but 16 will snap to 20.
|
||||
*
|
||||
* @method snapToCeil
|
||||
* @method Phaser.Math#snapToCeil
|
||||
* @param {number} input - The value to snap.
|
||||
* @param {number} gap - The interval gap of the grid.
|
||||
* @param {number} [start] - Optional starting offset for gap.
|
||||
* @return {number}
|
||||
*/
|
||||
snapToCeil: function (input, gap, start) {
|
||||
|
||||
@@ -195,10 +200,11 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* Snaps a value to the nearest value in an array.
|
||||
* @method
|
||||
* @method Phaser.Math#snapToInArray
|
||||
* @param {number} input
|
||||
* @param {array} arr
|
||||
* @param {boolean} sort - True if the array needs to be sorted.
|
||||
* @return {number}
|
||||
*/
|
||||
snapToInArray: function (input, arr, sort) {
|
||||
|
||||
@@ -255,10 +261,11 @@ Phaser.Math = {
|
||||
* Note what occurs when we round to the 3rd space (8ths place), 100100000, this is to be assumed
|
||||
* because we are rounding 100011.1011011011011011 which rounds up.
|
||||
*
|
||||
* @method roundTo
|
||||
* @method Phaser.Math#roundTo
|
||||
* @param {number} value - The value to round.
|
||||
* @param {number} place - The place to round to.
|
||||
* @param {number} base - The base to round in... default is 10 for decimal.
|
||||
* @return {number}
|
||||
*/
|
||||
roundTo: function (value, place, base) {
|
||||
|
||||
@@ -272,10 +279,11 @@ Phaser.Math = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @method floorTo
|
||||
* @method Phaser.Math#floorTo
|
||||
* @param {number} value - The value to round.
|
||||
* @param {number} place - The place to round to.
|
||||
* @param {number} base - The base to round in... default is 10 for decimal.
|
||||
* @return {number}
|
||||
*/
|
||||
floorTo: function (value, place, base) {
|
||||
|
||||
@@ -289,10 +297,11 @@ Phaser.Math = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @method ceilTo
|
||||
* @method Phaser.Math#ceilTo
|
||||
* @param {number} value - The value to round.
|
||||
* @param {number} place - The place to round to.
|
||||
* @param {number} base - The base to round in... default is 10 for decimal.
|
||||
* @return {number}
|
||||
*/
|
||||
ceilTo: function (value, place, base) {
|
||||
|
||||
@@ -307,10 +316,11 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* A one dimensional linear interpolation of a value.
|
||||
* @method interpolateFloat
|
||||
* @method Phaser.Math#interpolateFloat
|
||||
* @param {number} a
|
||||
* @param {number} b
|
||||
* @param {number} weight
|
||||
* @return {number}
|
||||
*/
|
||||
interpolateFloat: function (a, b, weight) {
|
||||
return (b - a) * weight + a;
|
||||
@@ -318,11 +328,12 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* Find the angle of a segment from (x1, y1) -> (x2, y2 ).
|
||||
* @method angleBetween
|
||||
* @method Phaser.Math#angleBetween
|
||||
* @param {number} x1
|
||||
* @param {number} y1
|
||||
* @param {number} x2
|
||||
* @param {number} y2
|
||||
* @return {number}
|
||||
*/
|
||||
angleBetween: function (x1, y1, x2, y2) {
|
||||
return Math.atan2(y2 - y1, x2 - x1);
|
||||
@@ -330,9 +341,10 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* Set an angle within the bounds of -π toπ.
|
||||
* @method normalizeAngle
|
||||
* @method Phaser.Math#normalizeAngle
|
||||
* @param {number} angle
|
||||
* @param {boolean} radians - True if angle size is expressed in radians.
|
||||
* @return {number}
|
||||
*/
|
||||
normalizeAngle: function (angle, radians) {
|
||||
|
||||
@@ -346,10 +358,11 @@ Phaser.Math = {
|
||||
/**
|
||||
* Closest angle between two angles from a1 to a2
|
||||
* absolute value the return for exact angle
|
||||
* @method nearestAngleBetween
|
||||
* @method Phaser.Math#nearestAngleBetween
|
||||
* @param {number} a1
|
||||
* @param {number} a2
|
||||
* @param {boolean} radians - True if angle sizes are expressed in radians.
|
||||
* @return {number}
|
||||
*/
|
||||
nearestAngleBetween: function (a1, a2, radians) {
|
||||
|
||||
@@ -375,12 +388,13 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* Interpolate across the shortest arc between two angles.
|
||||
* @method interpolateAngles
|
||||
* @method Phaser.Math#interpolateAngles
|
||||
* @param {number} a1 - Description.
|
||||
* @param {number} a2 - Description.
|
||||
* @param {number} weight - Description.
|
||||
* @param {boolean} radians - True if angle sizes are expressed in radians.
|
||||
* @param {Description} ease - Description.
|
||||
* @return {number}
|
||||
*/
|
||||
interpolateAngles: function (a1, a2, weight, radians, ease) {
|
||||
|
||||
@@ -400,7 +414,7 @@ Phaser.Math = {
|
||||
* Returns true or false based on the chance value (default 50%). For example if you wanted a player to have a 30% chance
|
||||
* of getting a bonus, call chanceRoll(30) - true means the chance passed, false means it failed.
|
||||
* </p>
|
||||
* @method chanceRoll
|
||||
* @method Phaser.Math#chanceRoll
|
||||
* @param {number} chance - The chance of receiving the value. A number between 0 and 100 (effectively 0% to 100%).
|
||||
* @return {boolean} True if the roll passed, or false otherwise.
|
||||
*/
|
||||
@@ -433,7 +447,7 @@ Phaser.Math = {
|
||||
/**
|
||||
* Returns an Array containing the numbers from min to max (inclusive).
|
||||
*
|
||||
* @method numberArray
|
||||
* @method Phaser.Math#numberArray
|
||||
* @param {number} min - The minimum value the array starts with.
|
||||
* @param {number} max - The maximum value the array contains.
|
||||
* @return {array} The array of number values.
|
||||
@@ -454,11 +468,11 @@ Phaser.Math = {
|
||||
/**
|
||||
* Adds the given amount to the value, but never lets the value go over the specified maximum.
|
||||
*
|
||||
* @method maxAdd
|
||||
* @method Phaser.Math#maxAdd
|
||||
* @param {number} value - The value to add the amount to.
|
||||
* @param {number} amount - The amount to add to the value.
|
||||
* @param {number} max- The maximum the value is allowed to be.
|
||||
* @return The new value.
|
||||
* @return {number}
|
||||
*/
|
||||
maxAdd: function (value, amount, max) {
|
||||
|
||||
@@ -476,7 +490,7 @@ Phaser.Math = {
|
||||
/**
|
||||
* Subtracts the given amount from the value, but never lets the value go below the specified minimum.
|
||||
*
|
||||
* @method minSub
|
||||
* @method Phaser.Math#minSub
|
||||
* @param {number} value - The base value.
|
||||
* @param {number} amount - The amount to subtract from the base value.
|
||||
* @param {number} min - The minimum the value is allowed to be.
|
||||
@@ -499,10 +513,11 @@ Phaser.Math = {
|
||||
* Ensures that the value always stays between min and max, by wrapping the value around.
|
||||
* <p>max should be larger than min, or the function will return 0</p>
|
||||
*
|
||||
* @method Phaser.Math#wrap
|
||||
* @param value The value to wrap
|
||||
* @param min The minimum the value is allowed to be
|
||||
* @param max The maximum the value is allowed to be
|
||||
* @return The wrapped value
|
||||
* @return {number} The wrapped value
|
||||
*/
|
||||
wrap: function (value, min, max) {
|
||||
|
||||
@@ -523,12 +538,11 @@ Phaser.Math = {
|
||||
* Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around.
|
||||
* <p>Values must be positive integers, and are passed through Math.abs</p>
|
||||
*
|
||||
* @method wrapValue
|
||||
* @method Phaser.Math#wrapValue
|
||||
* @param {number} value - The value to add the amount to.
|
||||
* @param {number} amount - The amount to add to the value.
|
||||
* @param {number} max - The maximum the value is allowed to be.
|
||||
* @return {number} The wrapped value.
|
||||
|
||||
*/
|
||||
wrapValue: function (value, amount, max) {
|
||||
|
||||
@@ -545,7 +559,7 @@ Phaser.Math = {
|
||||
/**
|
||||
* Randomly returns either a 1 or -1.
|
||||
*
|
||||
* @method randomSign
|
||||
* @method Phaser.Math#randomSign
|
||||
* @return {number} 1 or -1
|
||||
*/
|
||||
randomSign: function () {
|
||||
@@ -555,8 +569,8 @@ Phaser.Math = {
|
||||
/**
|
||||
* Returns true if the number given is odd.
|
||||
*
|
||||
* @method isOdd
|
||||
* @param {number} n - The number to check.
|
||||
* @method Phaser.Math#isOdd
|
||||
* @param {number} n - The number to check.
|
||||
* @return {boolean} True if the given number is odd. False if the given number is even.
|
||||
*/
|
||||
isOdd: function (n) {
|
||||
@@ -568,8 +582,8 @@ Phaser.Math = {
|
||||
/**
|
||||
* Returns true if the number given is even.
|
||||
*
|
||||
* @method isEven
|
||||
* @param {number} n - The number to check.
|
||||
* @method Phaser.Math#isEven
|
||||
* @param {number} n - The number to check.
|
||||
* @return {boolean} True if the given number is even. False if the given number is odd.
|
||||
*/
|
||||
isEven: function (n) {
|
||||
@@ -587,10 +601,10 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* Significantly faster version of Math.max
|
||||
* See {@link http://jsperf.com/math-s-min-max-vs-homemade/5}
|
||||
* See http://jsperf.com/math-s-min-max-vs-homemade/5
|
||||
*
|
||||
* @method max
|
||||
* @return The highest value from those given.
|
||||
* @method Phaser.Math#max
|
||||
* @return {number} The highest value from those given.
|
||||
*/
|
||||
max: function () {
|
||||
|
||||
@@ -608,10 +622,10 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* Significantly faster version of Math.min
|
||||
* See {@link http://jsperf.com/math-s-min-max-vs-homemade/5}
|
||||
* See http://jsperf.com/math-s-min-max-vs-homemade/5
|
||||
*
|
||||
* @method min
|
||||
* @return The lowest value from those given.
|
||||
* @method Phaser.Math#min
|
||||
* @return {number} The lowest value from those given.
|
||||
*/
|
||||
min: function () {
|
||||
|
||||
@@ -631,7 +645,7 @@ Phaser.Math = {
|
||||
* Keeps an angle value between -180 and +180<br>
|
||||
* Should be called whenever the angle is updated on the Sprite to stop it from going insane.
|
||||
*
|
||||
* @method wrapAngle
|
||||
* @method Phaser.Math#wrapAngle
|
||||
* @param {number} angle - The angle value to check
|
||||
* @return {number} The new angle value, returns the same as the input angle if it was within bounds.
|
||||
*/
|
||||
@@ -660,7 +674,7 @@ Phaser.Math = {
|
||||
/**
|
||||
* Keeps an angle value between the given min and max values.
|
||||
*
|
||||
* @method angleLimit
|
||||
* @method Phaser.Math#angleLimit
|
||||
* @param {number} angle - The angle value to check. Must be between -180 and +180.
|
||||
* @param {number} min - The minimum angle that is allowed (must be -180 or greater).
|
||||
* @param {number} max - The maximum angle that is allowed (must be 180 or less).
|
||||
@@ -679,7 +693,7 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method linearInterpolation
|
||||
* @method Phaser.Math#linearInterpolation
|
||||
* @param {number} v
|
||||
* @param {number} k
|
||||
* @return {number}
|
||||
@@ -699,7 +713,7 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method bezierInterpolation
|
||||
* @method Phaser.Math#bezierInterpolation
|
||||
* @param {number} v
|
||||
* @param {number} k
|
||||
* @return {number}
|
||||
@@ -715,7 +729,7 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method catmullRomInterpolation
|
||||
* @method Phaser.Math#catmullRomInterpolation
|
||||
* @param {number} v
|
||||
* @param {number} k
|
||||
* @return {number}
|
||||
@@ -744,7 +758,7 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method Linear
|
||||
* @method Phaser.Math#Linear
|
||||
* @param {number} p0
|
||||
* @param {number} p1
|
||||
* @param {number} t
|
||||
@@ -755,7 +769,7 @@ Phaser.Math = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @method bernstein
|
||||
* @method Phaser.Math#bernstein
|
||||
* @param {number} n
|
||||
* @param {number} i
|
||||
* @return {number}
|
||||
@@ -766,7 +780,7 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method catmullRom
|
||||
* @method Phaser.Math#catmullRom
|
||||
* @param {number} p0
|
||||
* @param {number} p1
|
||||
* @param {number} p2
|
||||
@@ -779,6 +793,12 @@ Phaser.Math = {
|
||||
return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.Math#difference
|
||||
* @param {number} a
|
||||
* @param {number} b
|
||||
* @return {number}
|
||||
*/
|
||||
difference: function (a, b) {
|
||||
return Math.abs(a - b);
|
||||
},
|
||||
@@ -787,11 +807,11 @@ Phaser.Math = {
|
||||
* Fetch a random entry from the given array.
|
||||
* Will return null if random selection is missing, or array has no entries.
|
||||
*
|
||||
* @method getRandom
|
||||
* @param objects An array of objects.
|
||||
* @param startIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
|
||||
* @param length Optional restriction on the number of values you want to randomly select from.
|
||||
* @return The random object that was selected.
|
||||
* @method Phaser.Math#getRandom
|
||||
* @param {array} objects - An array of objects.
|
||||
* @param {number} startIndex - Optional offset off the front of the array. Default value is 0, or the beginning of the array.
|
||||
* @param {number} length - Optional restriction on the number of values you want to randomly select from.
|
||||
* @return {object} The random object that was selected.
|
||||
*/
|
||||
getRandom: function (objects, startIndex, length) {
|
||||
|
||||
@@ -820,7 +840,7 @@ Phaser.Math = {
|
||||
/**
|
||||
* Round down to the next whole number. E.g. floor(1.7) == 1, and floor(-2.7) == -2.
|
||||
*
|
||||
* @method floor
|
||||
* @method Phaser.Math#floor
|
||||
* @param {number} Value Any number.
|
||||
* @return {number} The rounded value of that number.
|
||||
*/
|
||||
@@ -835,9 +855,9 @@ Phaser.Math = {
|
||||
/**
|
||||
* Round up to the next whole number. E.g. ceil(1.3) == 2, and ceil(-2.3) == -3.
|
||||
*
|
||||
* @param Value Any number.
|
||||
*
|
||||
* @return The rounded value of that number.
|
||||
* @method Phaser.Math#ceil
|
||||
* @param {number} value - Any number.
|
||||
* @return {number} The rounded value of that number.
|
||||
*/
|
||||
ceil: function (value) {
|
||||
var n = value | 0;
|
||||
@@ -850,13 +870,12 @@ Phaser.Math = {
|
||||
* The parameters allow you to specify the length, amplitude and frequency of the wave. Once you have called this function
|
||||
* you should get the results via getSinTable() and getCosTable(). This generator is fast enough to be used in real-time.
|
||||
* </p>
|
||||
* @param length The length of the wave
|
||||
* @param sinAmplitude The amplitude to apply to the sine table (default 1.0) if you need values between say -+ 125 then give 125 as the value
|
||||
* @param cosAmplitude The amplitude to apply to the cosine table (default 1.0) if you need values between say -+ 125 then give 125 as the value
|
||||
* @param frequency The frequency of the sine and cosine table data
|
||||
* @return Returns the sine table
|
||||
* @see getSinTable
|
||||
* @see getCosTable
|
||||
* @method Phaser.Math#sinCosGenerator
|
||||
* @param {number} length - The length of the wave
|
||||
* @param {number} sinAmplitude - The amplitude to apply to the sine table (default 1.0) if you need values between say -+ 125 then give 125 as the value
|
||||
* @param {number} cosAmplitude - The amplitude to apply to the cosine table (default 1.0) if you need values between say -+ 125 then give 125 as the value
|
||||
* @param {number} frequency - The frequency of the sine and cosine table data
|
||||
* @return {Array} Returns the sine table
|
||||
*/
|
||||
sinCosGenerator: function (length, sinAmplitude, cosAmplitude, frequency) {
|
||||
|
||||
@@ -887,9 +906,11 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* Removes the top element from the stack and re-inserts it onto the bottom, then returns it.
|
||||
* The original stack is modified in the process.
|
||||
* This effectively moves the position of the data from the start to the end of the table.
|
||||
* @return The value.
|
||||
* The original stack is modified in the process. This effectively moves the position of the data from the start to the end of the table.
|
||||
*
|
||||
* @method Phaser.Math#shift
|
||||
* @param {array} stack - The array to shift.
|
||||
* @return {any} The shifted value.
|
||||
*/
|
||||
shift: function (stack) {
|
||||
|
||||
@@ -902,8 +923,9 @@ Phaser.Math = {
|
||||
|
||||
/**
|
||||
* Shuffles the data in the given array into a new order
|
||||
* @param array The array to shuffle
|
||||
* @return The array
|
||||
* @method Phaser.Math#shuffleArray
|
||||
* @param {array} array - The array to shuffle
|
||||
* @return {array} The array
|
||||
*/
|
||||
shuffleArray: function (array) {
|
||||
|
||||
@@ -922,7 +944,7 @@ Phaser.Math = {
|
||||
/**
|
||||
* Returns the distance between the two given set of coordinates.
|
||||
*
|
||||
* @method distance
|
||||
* @method Phaser.Math#distance
|
||||
* @param {number} x1
|
||||
* @param {number} y1
|
||||
* @param {number} x2
|
||||
@@ -938,6 +960,16 @@ Phaser.Math = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the rounded distance between the two given set of coordinates.
|
||||
*
|
||||
* @method Phaser.Math#distanceRounded
|
||||
* @param {number} x1
|
||||
* @param {number} y1
|
||||
* @param {number} x2
|
||||
* @param {number} y2
|
||||
* @return {number} The distance between this Point object and the destination Point object.
|
||||
**/
|
||||
distanceRounded: function (x1, y1, x2, y2) {
|
||||
|
||||
return Math.round(Phaser.Math.distance(x1, y1, x2, y2));
|
||||
@@ -948,10 +980,11 @@ Phaser.Math = {
|
||||
* Force a value within the boundaries of two values.
|
||||
* Clamp value to range <a, b>
|
||||
*
|
||||
* @method clamp
|
||||
* @method Phaser.Math#clamp
|
||||
* @param {number} x
|
||||
* @param {number} a
|
||||
* @param {number} b
|
||||
* @return {number}
|
||||
*/
|
||||
clamp: function ( x, a, b ) {
|
||||
|
||||
@@ -962,9 +995,10 @@ Phaser.Math = {
|
||||
/**
|
||||
* Clamp value to range <a, inf).
|
||||
*
|
||||
* @method clampBottom
|
||||
* @method Phaser.Math#clampBottom
|
||||
* @param {number} x
|
||||
* @param {number} a
|
||||
* @return {number}
|
||||
*/
|
||||
clampBottom: function ( x, a ) {
|
||||
|
||||
@@ -975,7 +1009,7 @@ Phaser.Math = {
|
||||
/**
|
||||
* Linear mapping from range <a1, a2> to range <b1, b2>
|
||||
*
|
||||
* @method mapLinear
|
||||
* @method Phaser.Math#mapLinear
|
||||
* @param {number} x
|
||||
* @param {number} a1
|
||||
* @param {number} a1
|
||||
@@ -990,11 +1024,10 @@ Phaser.Math = {
|
||||
|
||||
},
|
||||
|
||||
//
|
||||
/**
|
||||
* {@link http://en.wikipedia.org/wiki/Smoothstep}
|
||||
* Smoothstep function as detailed at http://en.wikipedia.org/wiki/Smoothstep
|
||||
*
|
||||
* @method smoothstep
|
||||
* @method Phaser.Math#smoothstep
|
||||
* @param {number} x
|
||||
* @param {number} min
|
||||
* @param {number} max
|
||||
@@ -1012,9 +1045,9 @@ Phaser.Math = {
|
||||
},
|
||||
|
||||
/**
|
||||
* {@link http://en.wikipedia.org/wiki/Smoothstep}
|
||||
* Smootherstep function as detailed at http://en.wikipedia.org/wiki/Smoothstep
|
||||
*
|
||||
* @method smootherstep
|
||||
* @method Phaser.Math#smootherstep
|
||||
* @param {number} x
|
||||
* @param {number} min
|
||||
* @param {number} max
|
||||
@@ -1035,7 +1068,7 @@ Phaser.Math = {
|
||||
* A value representing the sign of the value.
|
||||
* -1 for negative, +1 for positive, 0 if value is 0
|
||||
*
|
||||
* @method sign
|
||||
* @method Phaser.Math#sign
|
||||
* @param {number} x
|
||||
* @return {number}
|
||||
*/
|
||||
@@ -1048,7 +1081,7 @@ Phaser.Math = {
|
||||
/**
|
||||
* Convert degrees to radians.
|
||||
*
|
||||
* @method degToRad
|
||||
* @method Phaser.Math#degToRad
|
||||
* @return {function}
|
||||
*/
|
||||
degToRad: function() {
|
||||
@@ -1066,7 +1099,7 @@ Phaser.Math = {
|
||||
/**
|
||||
* Convert degrees to radians.
|
||||
*
|
||||
* @method radToDeg
|
||||
* @method Phaser.Math#radToDeg
|
||||
* @return {function}
|
||||
*/
|
||||
radToDeg: function() {
|
||||
|
||||
+7
-11
@@ -2,7 +2,6 @@
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.Quadtree
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -47,11 +46,8 @@
|
||||
* QuadTree Constructor
|
||||
*
|
||||
* @class Phaser.QuadTree
|
||||
* @classdesc Javascript QuadTree <p>
|
||||
* The original code was a conversion of the Java code posted to GameDevTuts. However I've tweaked
|
||||
* it massively to add node indexing, removed lots of temp. var creation and significantly
|
||||
* increased performance as a result.<p>
|
||||
* Original version at {@link https://github.com/timohausmann/quadtree-js/}
|
||||
* @classdesc A QuadTree implementation. The original code was a conversion of the Java code posted to GameDevTuts. However I've tweaked
|
||||
* it massively to add node indexing, removed lots of temp. var creation and significantly increased performance as a result. Original version at https://github.com/timohausmann/quadtree-js/
|
||||
* @constructor
|
||||
* @param {Description} physicsManager - Description.
|
||||
* @param {Description} x - Description.
|
||||
@@ -93,7 +89,7 @@ Phaser.QuadTree.prototype = {
|
||||
/*
|
||||
* Split the node into 4 subnodes
|
||||
*
|
||||
* @method split
|
||||
* @method Phaser.QuadTree#split
|
||||
*/
|
||||
split: function() {
|
||||
|
||||
@@ -118,7 +114,7 @@ Phaser.QuadTree.prototype = {
|
||||
* exceeds the capacity, it will split and add all
|
||||
* objects to their corresponding subnodes.
|
||||
*
|
||||
* @method insert
|
||||
* @method Phaser.QuadTree#insert
|
||||
* @param {object} body - Description.
|
||||
*/
|
||||
insert: function (body) {
|
||||
@@ -169,7 +165,7 @@ Phaser.QuadTree.prototype = {
|
||||
/*
|
||||
* Determine which node the object belongs to.
|
||||
*
|
||||
* @method getIndex
|
||||
* @method Phaser.QuadTree#getIndex
|
||||
* @param {object} rect - Description.
|
||||
* @return {number} index - Index of the subnode (0-3), or -1 if rect cannot completely fit within a subnode and is part of the parent node.
|
||||
*/
|
||||
@@ -213,7 +209,7 @@ Phaser.QuadTree.prototype = {
|
||||
/*
|
||||
* Return all objects that could collide with the given object.
|
||||
*
|
||||
* @method retrieve
|
||||
* @method Phaser.QuadTree#retrieve
|
||||
* @param {object} rect - Description.
|
||||
* @Return {array} - Array with all detected objects.
|
||||
*/
|
||||
@@ -249,7 +245,7 @@ Phaser.QuadTree.prototype = {
|
||||
|
||||
/*
|
||||
* Clear the quadtree.
|
||||
* @method clear
|
||||
* @method Phaser.QuadTree#clear
|
||||
*/
|
||||
clear: function () {
|
||||
|
||||
|
||||
@@ -2,17 +2,15 @@
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.RandomDataGenerator
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Phaser.RandomDataGenerator constructor.
|
||||
*
|
||||
* @class Phaser.RandomDataGenerator
|
||||
* @classdesc An extremely useful repeatable random data generator. Access it via Phaser.Game.rnd
|
||||
* Based on Nonsense by Josh Faul {@link https://github.com/jocafa/Nonsense}.
|
||||
* Random number generator from {@link http://baagoe.org/en/wiki/Better_random_numbers_for_javascript}
|
||||
* Based on Nonsense by Josh Faul https://github.com/jocafa/Nonsense.
|
||||
* Random number generator from http://baagoe.org/en/wiki/Better_random_numbers_for_javascript
|
||||
*
|
||||
* @constructor
|
||||
* @param {array} seeds
|
||||
@@ -53,7 +51,7 @@ Phaser.RandomDataGenerator.prototype = {
|
||||
|
||||
/**
|
||||
* Private random helper.
|
||||
* @method rnd
|
||||
* @method Phaser.RandomDataGenerator#rnd
|
||||
* @private
|
||||
* @return {number} Description.
|
||||
*/
|
||||
@@ -72,7 +70,7 @@ Phaser.RandomDataGenerator.prototype = {
|
||||
/**
|
||||
* Reset the seed of the random data generator.
|
||||
*
|
||||
* @method sow
|
||||
* @method Phaser.RandomDataGenerator#sow
|
||||
* @param {array} seeds
|
||||
*/
|
||||
sow: function (seeds) {
|
||||
@@ -98,7 +96,7 @@ Phaser.RandomDataGenerator.prototype = {
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method hash
|
||||
* @method Phaser.RandomDataGenerator#hash
|
||||
* @param {Any} data
|
||||
* @private
|
||||
* @return {number} Description.
|
||||
@@ -126,7 +124,7 @@ Phaser.RandomDataGenerator.prototype = {
|
||||
|
||||
/**
|
||||
* Returns a random integer between 0 and 2^32.
|
||||
* @method integer
|
||||
* @method Phaser.RandomDataGenerator#integer
|
||||
* @return {number}
|
||||
*/
|
||||
integer: function() {
|
||||
@@ -135,7 +133,7 @@ Phaser.RandomDataGenerator.prototype = {
|
||||
|
||||
/**
|
||||
* Returns a random real number between 0 and 1.
|
||||
* @method frac
|
||||
* @method Phaser.RandomDataGenerator#frac
|
||||
* @return {number}
|
||||
*/
|
||||
frac: function() {
|
||||
@@ -144,7 +142,7 @@ Phaser.RandomDataGenerator.prototype = {
|
||||
|
||||
/**
|
||||
* Returns a random real number between 0 and 2^32.
|
||||
* @method real
|
||||
* @method Phaser.RandomDataGenerator#real
|
||||
* @return {number}
|
||||
*/
|
||||
real: function() {
|
||||
@@ -153,7 +151,7 @@ Phaser.RandomDataGenerator.prototype = {
|
||||
|
||||
/**
|
||||
* Returns a random integer between min and max.
|
||||
* @method integerInRange
|
||||
* @method Phaser.RandomDataGenerator#integerInRange
|
||||
* @param {number} min
|
||||
* @param {number} max
|
||||
* @return {number}
|
||||
@@ -164,7 +162,7 @@ Phaser.RandomDataGenerator.prototype = {
|
||||
|
||||
/**
|
||||
* Returns a random real number between min and max.
|
||||
* @method realInRange
|
||||
* @method Phaser.RandomDataGenerator#realInRange
|
||||
* @param {number} min
|
||||
* @param {number} max
|
||||
* @return {number}
|
||||
@@ -180,7 +178,7 @@ Phaser.RandomDataGenerator.prototype = {
|
||||
|
||||
/**
|
||||
* Returns a random real number between -1 and 1.
|
||||
* @method normal
|
||||
* @method Phaser.RandomDataGenerator#normal
|
||||
* @return {number}
|
||||
*/
|
||||
normal: function () {
|
||||
@@ -188,8 +186,8 @@ Phaser.RandomDataGenerator.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a valid RFC4122 version4 ID hex string (from {@link https://gist.github.com/1308368}).
|
||||
* @method uuid
|
||||
* Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368
|
||||
* @method Phaser.RandomDataGenerator#uuid
|
||||
* @return {string}
|
||||
*/
|
||||
uuid: function () {
|
||||
@@ -208,7 +206,7 @@ Phaser.RandomDataGenerator.prototype = {
|
||||
|
||||
/**
|
||||
* Returns a random member of `array`.
|
||||
* @method pick
|
||||
* @method Phaser.RandomDataGenerator#pick
|
||||
* @param {Any} ary
|
||||
* @return {number}
|
||||
*/
|
||||
@@ -218,7 +216,7 @@ Phaser.RandomDataGenerator.prototype = {
|
||||
|
||||
/**
|
||||
* Returns a random member of `array`, favoring the earlier entries.
|
||||
* @method weightedPick
|
||||
* @method Phaser.RandomDataGenerator#weightedPick
|
||||
* @param {Any} ary
|
||||
* @return {number}
|
||||
*/
|
||||
@@ -228,7 +226,7 @@ Phaser.RandomDataGenerator.prototype = {
|
||||
|
||||
/**
|
||||
* Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified.
|
||||
* @method timestamp
|
||||
* @method Phaser.RandomDataGenerator#timestamp
|
||||
* @param {number} min
|
||||
* @param {number} max
|
||||
* @return {number}
|
||||
@@ -239,7 +237,7 @@ Phaser.RandomDataGenerator.prototype = {
|
||||
|
||||
/**
|
||||
* Returns a random angle between -180 and 180.
|
||||
* @method angle
|
||||
* @method Phaser.RandomDataGenerator#angle
|
||||
* @return {number}
|
||||
*/
|
||||
angle: function() {
|
||||
|
||||
Reference in New Issue
Block a user