Skip to content

Commit 96de58c

Browse files
committed
Added lots more info to the jsdocs and tidied up the code for phaserjs#2056
1 parent a445a99 commit 96de58c

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
266266
* Tiled 0.13.0 added support for layer data compression when exporting as JSON. This means that any .tmx stored using base64 encoding will start exporting layer data as a base64 encoded string rather than a native array. This update adds in automatic support for this as long as the data isn't compressed. For IE9 support you'll need to use the new polyfill found in the resources folder (thanks @noidexe #2084)
267267
* You can now load single layer Pyxel Edit TileMaps as an atlas (thanks @joshpmcghee #2050)
268268
* Canvas.getSmoothingPrefix will return the vendor prefixed smoothing enabled value from the context if set, otherwise null.
269+
* The Random Number Generator can now get and set its state via rnd.state. This allows you to do things like saving the state of the generator to a string that can be part of a save-game file and load it back in again (thanks @luckylooke #2056 #1900)
269270

270271
### Updates
271272

@@ -283,6 +284,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
283284
* DeviceButton was setting a `duration` property on itself, which went against the read only getter of duration (thanks @winstonwolff)
284285
* Added Node.js v4 stable to Travis config (thanks @phillipalexander #2070)
285286
* Optimised Canvas.getSmoothingEnabled, Canvas.setSmoothingEnabled and Canvas.setImageRenderingCrisp.
287+
* The Physics Editor Exporter (found in the resources folder of the repo) has had an option to prefix shape names and optimize JSON output added to it (thanks @Garbanas #2093)
286288

287289
### Bug Fixes
288290

@@ -293,6 +295,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
293295
* Game.update could call `updateLogic` multiple times in a single frame when catching up with slow device frame rates. This would cause Tweens to advance at twice the speed they should have done (thanks @mkristo)
294296
* Added useCapture flags to removeEventListener in MSPointer class (thanks @pmcmonagle #2055)
295297
* Under setTimeOut (or when `forceSetTimeOut` was true) the Time was incorrectly setting `Time.timeExpected` causing game updates to lag (thanks @satan6 #2087)
298+
* Fixes edge case when TilingSprite is removed before render (thanks @pnstickne #2097 #2092)
296299

297300
### Pixi Updates
298301

src/math/RandomDataGenerator.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @class Phaser.RandomDataGenerator
2020
* @constructor
21-
* @param {any[]|String} [seeds] - An array of values to use as the seed or a generator state (from {#state}).
21+
* @param {any[]|string} [seeds] - An array of values to use as the seed, or a generator state (from {#state}).
2222
*/
2323
Phaser.RandomDataGenerator = function (seeds) {
2424

@@ -48,9 +48,12 @@ Phaser.RandomDataGenerator = function (seeds) {
4848
*/
4949
this.s2 = 0;
5050

51-
if((typeof seeds === 'string' || seeds instanceof String) && seeds.match(/^!rnd/)){
51+
if (typeof seeds === 'string')
52+
{
5253
this.state(seeds);
53-
}else{
54+
}
55+
else
56+
{
5457
this.sow(seeds);
5558
}
5659

@@ -305,21 +308,34 @@ Phaser.RandomDataGenerator.prototype = {
305308
},
306309

307310
/**
308-
* Sets or gets state of the generator
311+
* Gets or Sets the state of the generator. This allows you to retain the values
312+
* that the generator is using between games, i.e. in a game save file.
313+
*
314+
* To seed this generator with a previously saved state you can pass it as the
315+
* `seed` value in your game config, or call this method directly after Phaser has booted.
316+
*
317+
* Call this method with no parameters to return the current state.
318+
*
319+
* If providing a state it should match the same format that this method
320+
* returns, which is a string with a header `!rnd` followed by the `c`,
321+
* `s0`, `s1` and `s2` values respectively, each comma-delimited.
309322
*
310323
* @method Phaser.RandomDataGenerator#state
311-
* @param {String} [state] Generator state to be set.
312-
* @return {String} Actual generator state.
324+
* @param {string} [state] - Generator state to be set.
325+
* @return {string} The current state of the generator.
313326
*/
314327
state: function (state) {
315328

316-
if(state){
329+
if (typeof state === 'string' && seeds.match(/^!rnd/))
330+
{
317331
state = state.split(',');
332+
318333
this.c = parseFloat(state[1]);
319334
this.s0 = parseFloat(state[2]);
320335
this.s1 = parseFloat(state[3]);
321336
this.s2 = parseFloat(state[4]);
322337
}
338+
323339
return ['!rnd', this.c, this.s0, this.s1, this.s2].join(',');
324340

325341
}

0 commit comments

Comments
 (0)