mirror of
https://github.com/wassname/phaser.git
synced 2026-07-17 11:31:30 +08:00
Updated documentation.
This commit is contained in:
+233
-192
@@ -54,6 +54,10 @@
|
||||
<a href="Phaser.AnimationParser.html">AnimationParser</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.BitmapData.html">BitmapData</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.BitmapText.html">BitmapText</a>
|
||||
</li>
|
||||
@@ -138,6 +142,10 @@
|
||||
<a href="Phaser.Events.html">Events</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Filter.html">Filter</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Frame.html">Frame</a>
|
||||
</li>
|
||||
@@ -302,6 +310,26 @@
|
||||
<a href="Phaser.Text.html">Text</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Tile.html">Tile</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Tilemap.html">Tilemap</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.TilemapLayer.html">TilemapLayer</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.TilemapParser.html">TilemapParser</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Tileset.html">Tileset</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.TileSprite.html">TileSprite</a>
|
||||
</li>
|
||||
@@ -310,6 +338,10 @@
|
||||
<a href="Phaser.Time.html">Time</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Timer.html">Timer</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Touch.html">Touch</a>
|
||||
</li>
|
||||
@@ -356,6 +388,14 @@
|
||||
<a href="global.html#HEXtoRGB">HEXtoRGB</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#render">render</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#renderXY">renderXY</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#right">right</a>
|
||||
</li>
|
||||
@@ -381,7 +421,9 @@
|
||||
|
||||
<section>
|
||||
<article>
|
||||
<pre class="sunlight-highlight-javascript linenums">/**
|
||||
<pre class="sunlight-highlight-javascript linenums">/* jshint noempty: false */
|
||||
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
@@ -399,232 +441,231 @@
|
||||
* @param {array} seeds
|
||||
*/
|
||||
Phaser.RandomDataGenerator = function (seeds) {
|
||||
|
||||
if (typeof seeds === "undefined") { seeds = []; }
|
||||
|
||||
if (typeof seeds === "undefined") { seeds = []; }
|
||||
|
||||
this.sow(seeds);
|
||||
/**
|
||||
* @property {number} c - Internal var.
|
||||
* @private
|
||||
*/
|
||||
this.c = 1;
|
||||
|
||||
/**
|
||||
* @property {number} s0 - Internal var.
|
||||
* @private
|
||||
*/
|
||||
this.s0 = 0;
|
||||
|
||||
/**
|
||||
* @property {number} s1 - Internal var.
|
||||
* @private
|
||||
*/
|
||||
this.s1 = 0;
|
||||
|
||||
/**
|
||||
* @property {number} s2 - Internal var.
|
||||
* @private
|
||||
*/
|
||||
this.s2 = 0;
|
||||
|
||||
this.sow(seeds);
|
||||
|
||||
};
|
||||
|
||||
Phaser.RandomDataGenerator.prototype = {
|
||||
|
||||
/**
|
||||
* @property {number} c
|
||||
* @private
|
||||
*/
|
||||
c: 1,
|
||||
/**
|
||||
* Private random helper.
|
||||
* @method Phaser.RandomDataGenerator#rnd
|
||||
* @private
|
||||
* @return {number}
|
||||
*/
|
||||
rnd: function () {
|
||||
|
||||
/**
|
||||
* @property {number} s0
|
||||
* @private
|
||||
*/
|
||||
s0: 0,
|
||||
var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10; // 2^-32
|
||||
|
||||
/**
|
||||
* @property {number} s1
|
||||
* @private
|
||||
*/
|
||||
s1: 0,
|
||||
this.c = t | 0;
|
||||
this.s0 = this.s1;
|
||||
this.s1 = this.s2;
|
||||
this.s2 = t - this.c;
|
||||
|
||||
/**
|
||||
* @property {number} s2
|
||||
* @private
|
||||
*/
|
||||
s2: 0,
|
||||
return this.s2;
|
||||
},
|
||||
|
||||
/**
|
||||
* Private random helper.
|
||||
* @method Phaser.RandomDataGenerator#rnd
|
||||
* @private
|
||||
* @return {number} Description.
|
||||
*/
|
||||
rnd: function () {
|
||||
/**
|
||||
* Reset the seed of the random data generator.
|
||||
*
|
||||
* @method Phaser.RandomDataGenerator#sow
|
||||
* @param {array} seeds
|
||||
*/
|
||||
sow: function (seeds) {
|
||||
|
||||
var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10; // 2^-32
|
||||
if (typeof seeds === "undefined") { seeds = []; }
|
||||
|
||||
this.c = t | 0;
|
||||
this.s0 = this.s1;
|
||||
this.s1 = this.s2;
|
||||
this.s2 = t - this.c;
|
||||
this.s0 = this.hash(' ');
|
||||
this.s1 = this.hash(this.s0);
|
||||
this.s2 = this.hash(this.s1);
|
||||
this.c = 1;
|
||||
|
||||
return this.s2;
|
||||
},
|
||||
var seed;
|
||||
|
||||
/**
|
||||
* Reset the seed of the random data generator.
|
||||
*
|
||||
* @method Phaser.RandomDataGenerator#sow
|
||||
* @param {array} seeds
|
||||
*/
|
||||
sow: function (seeds) {
|
||||
for (var i = 0; seed = seeds[i++]; )
|
||||
{
|
||||
this.s0 -= this.hash(seed);
|
||||
this.s0 += ~~(this.s0 < 0);
|
||||
this.s1 -= this.hash(seed);
|
||||
this.s1 += ~~(this.s1 < 0);
|
||||
this.s2 -= this.hash(seed);
|
||||
this.s2 += ~~(this.s2 < 0);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
if (typeof seeds === "undefined") { seeds = []; }
|
||||
/**
|
||||
* Internal method that creates a seed hash.
|
||||
* @method Phaser.RandomDataGenerator#hash
|
||||
* @param {Any} data
|
||||
* @private
|
||||
* @return {number} hashed value.
|
||||
*/
|
||||
hash: function (data) {
|
||||
|
||||
this.s0 = this.hash(' ');
|
||||
this.s1 = this.hash(this.s0);
|
||||
this.s2 = this.hash(this.s1);
|
||||
this.c = 1;
|
||||
var h, i, n;
|
||||
n = 0xefc8249d;
|
||||
data = data.toString();
|
||||
|
||||
var seed;
|
||||
for (i = 0; i < data.length; i++) {
|
||||
n += data.charCodeAt(i);
|
||||
h = 0.02519603282416938 * n;
|
||||
n = h >>> 0;
|
||||
h -= n;
|
||||
h *= n;
|
||||
n = h >>> 0;
|
||||
h -= n;
|
||||
n += h * 0x100000000;// 2^32
|
||||
}
|
||||
|
||||
for (var i = 0; seed = seeds[i++]; )
|
||||
{
|
||||
this.s0 -= this.hash(seed);
|
||||
this.s0 += ~~(this.s0 < 0);
|
||||
this.s1 -= this.hash(seed);
|
||||
this.s1 += ~~(this.s1 < 0);
|
||||
this.s2 -= this.hash(seed);
|
||||
this.s2 += ~~(this.s2 < 0);
|
||||
}
|
||||
|
||||
},
|
||||
return (n >>> 0) * 2.3283064365386963e-10;// 2^-32
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method Phaser.RandomDataGenerator#hash
|
||||
* @param {Any} data
|
||||
* @private
|
||||
* @return {number} Description.
|
||||
*/
|
||||
hash: function (data) {
|
||||
},
|
||||
|
||||
var h, i, n;
|
||||
n = 0xefc8249d;
|
||||
data = data.toString();
|
||||
/**
|
||||
* Returns a random integer between 0 and 2^32.
|
||||
* @method Phaser.RandomDataGenerator#integer
|
||||
* @return {number} A random integer between 0 and 2^32.
|
||||
*/
|
||||
integer: function() {
|
||||
return this.rnd.apply(this) * 0x100000000;// 2^32
|
||||
},
|
||||
|
||||
for (i = 0; i < data.length; i++) {
|
||||
n += data.charCodeAt(i);
|
||||
h = 0.02519603282416938 * n;
|
||||
n = h >>> 0;
|
||||
h -= n;
|
||||
h *= n;
|
||||
n = h >>> 0;
|
||||
h -= n;
|
||||
n += h * 0x100000000;// 2^32
|
||||
}
|
||||
/**
|
||||
* Returns a random real number between 0 and 1.
|
||||
* @method Phaser.RandomDataGenerator#frac
|
||||
* @return {number} A random real number between 0 and 1.
|
||||
*/
|
||||
frac: function() {
|
||||
return this.rnd.apply(this) + (this.rnd.apply(this) * 0x200000 | 0) * 1.1102230246251565e-16;// 2^-53
|
||||
},
|
||||
|
||||
return (n >>> 0) * 2.3283064365386963e-10;// 2^-32
|
||||
/**
|
||||
* Returns a random real number between 0 and 2^32.
|
||||
* @method Phaser.RandomDataGenerator#real
|
||||
* @return {number} A random real number between 0 and 2^32.
|
||||
*/
|
||||
real: function() {
|
||||
return this.integer() + this.frac();
|
||||
},
|
||||
|
||||
},
|
||||
/**
|
||||
* Returns a random integer between min and max.
|
||||
* @method Phaser.RandomDataGenerator#integerInRange
|
||||
* @param {number} min - The minimum value in the range.
|
||||
* @param {number} max - The maximum value in the range.
|
||||
* @return {number} A random number between min and max.
|
||||
*/
|
||||
integerInRange: function (min, max) {
|
||||
return Math.floor(this.realInRange(min, max));
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a random integer between 0 and 2^32.
|
||||
* @method Phaser.RandomDataGenerator#integer
|
||||
* @return {number}
|
||||
*/
|
||||
integer: function() {
|
||||
return this.rnd.apply(this) * 0x100000000;// 2^32
|
||||
},
|
||||
/**
|
||||
* Returns a random real number between min and max.
|
||||
* @method Phaser.RandomDataGenerator#realInRange
|
||||
* @param {number} min - The minimum value in the range.
|
||||
* @param {number} max - The maximum value in the range.
|
||||
* @return {number} A random number between min and max.
|
||||
*/
|
||||
realInRange: function (min, max) {
|
||||
|
||||
/**
|
||||
* Returns a random real number between 0 and 1.
|
||||
* @method Phaser.RandomDataGenerator#frac
|
||||
* @return {number}
|
||||
*/
|
||||
frac: function() {
|
||||
return this.rnd.apply(this) + (this.rnd.apply(this) * 0x200000 | 0) * 1.1102230246251565e-16;// 2^-53
|
||||
},
|
||||
return this.frac() * (max - min) + min;
|
||||
|
||||
/**
|
||||
* Returns a random real number between 0 and 2^32.
|
||||
* @method Phaser.RandomDataGenerator#real
|
||||
* @return {number}
|
||||
*/
|
||||
real: function() {
|
||||
return this.integer() + this.frac();
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a random integer between min and max.
|
||||
* @method Phaser.RandomDataGenerator#integerInRange
|
||||
* @param {number} min
|
||||
* @param {number} max
|
||||
* @return {number}
|
||||
*/
|
||||
integerInRange: function (min, max) {
|
||||
return Math.floor(this.realInRange(min, max));
|
||||
},
|
||||
/**
|
||||
* Returns a random real number between -1 and 1.
|
||||
* @method Phaser.RandomDataGenerator#normal
|
||||
* @return {number} A random real number between -1 and 1.
|
||||
*/
|
||||
normal: function () {
|
||||
return 1 - 2 * this.frac();
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a random real number between min and max.
|
||||
* @method Phaser.RandomDataGenerator#realInRange
|
||||
* @param {number} min
|
||||
* @param {number} max
|
||||
* @return {number}
|
||||
*/
|
||||
realInRange: function (min, max) {
|
||||
/**
|
||||
* Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368
|
||||
* @method Phaser.RandomDataGenerator#uuid
|
||||
* @return {string} A valid RFC4122 version4 ID hex string
|
||||
*/
|
||||
uuid: function () {
|
||||
|
||||
return this.frac() * (max - min) + min;
|
||||
var a = '';
|
||||
var b = '';
|
||||
|
||||
},
|
||||
for (b = a = ''; a++ < 36; b +=~a % 5 | a * 3&4 ? (a^15 ? 8^this.frac() * (a^20 ? 16 : 4) : 4).toString(16) : '-')
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random real number between -1 and 1.
|
||||
* @method Phaser.RandomDataGenerator#normal
|
||||
* @return {number}
|
||||
*/
|
||||
normal: function () {
|
||||
return 1 - 2 * this.frac();
|
||||
},
|
||||
return b;
|
||||
|
||||
/**
|
||||
* Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368
|
||||
* @method Phaser.RandomDataGenerator#uuid
|
||||
* @return {string}
|
||||
*/
|
||||
uuid: function () {
|
||||
},
|
||||
|
||||
var a, b;
|
||||
/**
|
||||
* Returns a random member of `array`.
|
||||
* @method Phaser.RandomDataGenerator#pick
|
||||
* @param {Array} ary - An Array to pick a random member of.
|
||||
* @return {any} A random member of the array.
|
||||
*/
|
||||
pick: function (ary) {
|
||||
return ary[this.integerInRange(0, ary.length)];
|
||||
},
|
||||
|
||||
for (
|
||||
b=a='';
|
||||
a++<36;
|
||||
b+=~a%5|a*3&4?(a^15?8^this.frac()*(a^20?16:4):4).toString(16):'-'
|
||||
);
|
||||
/**
|
||||
* Returns a random member of `array`, favoring the earlier entries.
|
||||
* @method Phaser.RandomDataGenerator#weightedPick
|
||||
* @param {Array} ary - An Array to pick a random member of.
|
||||
* @return {any} A random member of the array.
|
||||
*/
|
||||
weightedPick: function (ary) {
|
||||
return ary[~~(Math.pow(this.frac(), 2) * ary.length)];
|
||||
},
|
||||
|
||||
return b;
|
||||
/**
|
||||
* 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 Phaser.RandomDataGenerator#timestamp
|
||||
* @param {number} min - The minimum value in the range.
|
||||
* @param {number} max - The maximum value in the range.
|
||||
* @return {number} A random timestamp between min and max.
|
||||
*/
|
||||
timestamp: function (min, max) {
|
||||
return this.realInRange(min || 946684800000, max || 1577862000000);
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a random member of `array`.
|
||||
* @method Phaser.RandomDataGenerator#pick
|
||||
* @param {Any} ary
|
||||
* @return {number}
|
||||
*/
|
||||
pick: function (ary) {
|
||||
return ary[this.integerInRange(0, ary.length)];
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a random member of `array`, favoring the earlier entries.
|
||||
* @method Phaser.RandomDataGenerator#weightedPick
|
||||
* @param {Any} ary
|
||||
* @return {number}
|
||||
*/
|
||||
weightedPick: function (ary) {
|
||||
return ary[~~(Math.pow(this.frac(), 2) * ary.length)];
|
||||
},
|
||||
|
||||
/**
|
||||
* 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 Phaser.RandomDataGenerator#timestamp
|
||||
* @param {number} min
|
||||
* @param {number} max
|
||||
* @return {number}
|
||||
*/
|
||||
timestamp: function (a, b) {
|
||||
return this.realInRange(a || 946684800000, b || 1577862000000);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a random angle between -180 and 180.
|
||||
* @method Phaser.RandomDataGenerator#angle
|
||||
* @return {number}
|
||||
*/
|
||||
angle: function() {
|
||||
return this.integerInRange(-180, 180);
|
||||
}
|
||||
/**
|
||||
* Returns a random angle between -180 and 180.
|
||||
* @method Phaser.RandomDataGenerator#angle
|
||||
* @return {number} A random number between -180 and 180.
|
||||
*/
|
||||
angle: function() {
|
||||
return this.integerInRange(-180, 180);
|
||||
}
|
||||
|
||||
};
|
||||
</pre>
|
||||
@@ -648,7 +689,7 @@ Phaser.RandomDataGenerator.prototype = {
|
||||
|
||||
<span class="jsdoc-message">
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-dev</a>
|
||||
on Thu Nov 07 2013 06:07:33 GMT-0000 (GMT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
|
||||
on Thu Nov 28 2013 15:56:25 GMT-0000 (GMT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
|
||||
</span>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user