@vpmedia/phaser 1.0.36 → 1.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/phaser.cjs +1 -1
- package/dist/phaser.cjs.LICENSE.txt +1 -1
- package/dist/phaser.cjs.map +1 -1
- package/dist/phaser.js +1 -1
- package/dist/phaser.js.LICENSE.txt +1 -1
- package/dist/phaser.js.map +1 -1
- package/package.json +1 -1
- package/src/phaser/core/game.js +13 -33
- package/src/phaser/core/loader.js +1 -86
- package/src/phaser/core/raf.js +4 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vpmedia/phaser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.38",
|
|
4
4
|
"description": "@vpmedia/phaser is the modern ECMAScript port of the popular Phaser game engine v2.6.2",
|
|
5
5
|
"author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
|
|
6
6
|
"license": "MIT",
|
package/src/phaser/core/game.js
CHANGED
|
@@ -37,7 +37,6 @@ export default class {
|
|
|
37
37
|
this.renderer = null;
|
|
38
38
|
this.state = null;
|
|
39
39
|
this.isBooted = false;
|
|
40
|
-
this.isRunning = false;
|
|
41
40
|
this.raf = null;
|
|
42
41
|
this.add = null;
|
|
43
42
|
this.cache = null;
|
|
@@ -55,8 +54,9 @@ export default class {
|
|
|
55
54
|
this.isStepping = false;
|
|
56
55
|
this.isPendingStep = false;
|
|
57
56
|
this.stepCount = 0;
|
|
58
|
-
this.onPause =
|
|
59
|
-
this.onResume =
|
|
57
|
+
this.onPause = new Signal();
|
|
58
|
+
this.onResume = new Signal();
|
|
59
|
+
this.onBoot = new Signal();
|
|
60
60
|
this.isPaused = false;
|
|
61
61
|
this.currentUpdateID = 0;
|
|
62
62
|
this.updatesThisFrame = 1;
|
|
@@ -81,12 +81,9 @@ export default class {
|
|
|
81
81
|
|
|
82
82
|
boot() {
|
|
83
83
|
if (this.isBooted) {
|
|
84
|
-
console.warn('Game already booted.');
|
|
85
84
|
return;
|
|
86
85
|
}
|
|
87
86
|
this.isBooted = true;
|
|
88
|
-
this.onPause = new Signal();
|
|
89
|
-
this.onResume = new Signal();
|
|
90
87
|
this.scale = new ScaleManager(this, this.config.width, this.config.height);
|
|
91
88
|
this.stage = new Stage(this);
|
|
92
89
|
this.initRenderer();
|
|
@@ -105,13 +102,15 @@ export default class {
|
|
|
105
102
|
this.input.boot();
|
|
106
103
|
this.sound.boot();
|
|
107
104
|
this.state.boot();
|
|
108
|
-
this.isRunning = true;
|
|
109
|
-
this.raf = new RequestAnimationFrame(this);
|
|
110
105
|
this.isKickStart = true;
|
|
111
106
|
if (window.focus) {
|
|
112
107
|
window.focus();
|
|
113
108
|
}
|
|
114
|
-
this.
|
|
109
|
+
if (!this.config.isSkipTicker) {
|
|
110
|
+
this.raf = new RequestAnimationFrame(this);
|
|
111
|
+
this.raf.start();
|
|
112
|
+
}
|
|
113
|
+
this.onBoot.dispatch(this);
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
initRenderer() {
|
|
@@ -246,12 +245,6 @@ export default class {
|
|
|
246
245
|
}
|
|
247
246
|
|
|
248
247
|
update(time) {
|
|
249
|
-
if (this.isPendingDestroy) {
|
|
250
|
-
this.destroyDelayed();
|
|
251
|
-
return;
|
|
252
|
-
} else if (!this.isBooted) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
248
|
this.time.update(time);
|
|
256
249
|
if (this.isKickStart) {
|
|
257
250
|
this.updateLogic(this.time.desiredFpsMult);
|
|
@@ -260,7 +253,7 @@ export default class {
|
|
|
260
253
|
this.isKickStart = false;
|
|
261
254
|
return;
|
|
262
255
|
}
|
|
263
|
-
if (this._spiraling > 1
|
|
256
|
+
if (!this.config.forceSingleUpdate && this._spiraling > 1) {
|
|
264
257
|
// cause an event to warn the program that this CPU can't keep up with the current desiredFps rate
|
|
265
258
|
if (this.time.time > this._nextFpsNotification) {
|
|
266
259
|
// only permit one fps notification per 10 seconds
|
|
@@ -354,27 +347,14 @@ export default class {
|
|
|
354
347
|
}
|
|
355
348
|
|
|
356
349
|
destroy() {
|
|
357
|
-
if (this.isPendingDestroy) {
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
this.isPendingDestroy = true;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
destroyDelayed() {
|
|
364
|
-
if (!this.isPendingDestroy) {
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
this.isPendingDestroy = false;
|
|
368
|
-
|
|
369
350
|
this.isPaused = true;
|
|
370
|
-
this.isBooted = false;
|
|
371
|
-
this.isRunning = false;
|
|
372
351
|
|
|
373
|
-
if (!this.
|
|
352
|
+
if (!this.cache) {
|
|
374
353
|
return;
|
|
375
354
|
}
|
|
376
|
-
|
|
377
|
-
|
|
355
|
+
if (this.raf) {
|
|
356
|
+
this.raf.stop();
|
|
357
|
+
}
|
|
378
358
|
|
|
379
359
|
this.time.destroy();
|
|
380
360
|
this.state.destroy();
|
|
@@ -8,15 +8,11 @@ import Rectangle from '../geom/rectangle';
|
|
|
8
8
|
import { canPlayAudio } from './device_util';
|
|
9
9
|
import { TEXTURE_ATLAS_JSON_HASH } from './const';
|
|
10
10
|
|
|
11
|
-
export const TILED_JSON = 6;
|
|
12
|
-
export const TILEMAP_CSV = 7;
|
|
13
|
-
|
|
14
11
|
export default class {
|
|
15
12
|
|
|
16
13
|
constructor(game) {
|
|
17
14
|
this.game = game;
|
|
18
15
|
this.cache = game.cache;
|
|
19
|
-
this.resetLocked = false;
|
|
20
16
|
this.isLoading = false;
|
|
21
17
|
this.hasLoaded = false;
|
|
22
18
|
this.preloadSprite = null;
|
|
@@ -100,9 +96,6 @@ export default class {
|
|
|
100
96
|
}
|
|
101
97
|
|
|
102
98
|
reset(hard, clearEvents = false) {
|
|
103
|
-
if (this.resetLocked) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
99
|
if (hard) {
|
|
107
100
|
this.preloadSprite = null;
|
|
108
101
|
}
|
|
@@ -232,22 +225,10 @@ export default class {
|
|
|
232
225
|
return this.addToFileList('json', key, url, undefined, overwrite, '.json');
|
|
233
226
|
}
|
|
234
227
|
|
|
235
|
-
shader(key, url, overwrite) {
|
|
236
|
-
return this.addToFileList('shader', key, url, undefined, overwrite, '.frag');
|
|
237
|
-
}
|
|
238
|
-
|
|
239
228
|
xml(key, url, overwrite) {
|
|
240
229
|
return this.addToFileList('xml', key, url, undefined, overwrite, '.xml');
|
|
241
230
|
}
|
|
242
231
|
|
|
243
|
-
script(key, url, callback = false, callbackContext = this) {
|
|
244
|
-
return this.addToFileList('script', key, url, { syncPoint: true, callback, callbackContext }, false, '.js');
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
binary(key, url, callback = false, callbackContext = this) {
|
|
248
|
-
return this.addToFileList('binary', key, url, { callback, callbackContext }, false, '.bin');
|
|
249
|
-
}
|
|
250
|
-
|
|
251
232
|
spritesheet(key, url, frameWidth, frameHeight, frameMax = -1, margin = 0, spacing = 0) {
|
|
252
233
|
return this.addToFileList('spritesheet', key, url, { frameWidth, frameHeight, frameMax, margin, spacing }, false, '.png');
|
|
253
234
|
}
|
|
@@ -278,12 +259,6 @@ export default class {
|
|
|
278
259
|
return this;
|
|
279
260
|
}
|
|
280
261
|
|
|
281
|
-
tilemap() {
|
|
282
|
-
// TODO
|
|
283
|
-
console.warn('loader.tilemap() is not implemented');
|
|
284
|
-
return this;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
262
|
bitmapFont(key, textureURL = null, atlasURL = null, atlasData = null, xSpacing = 0, ySpacing = 0) {
|
|
288
263
|
if (textureURL === undefined || textureURL === null) {
|
|
289
264
|
textureURL = key + '.png';
|
|
@@ -509,12 +484,6 @@ export default class {
|
|
|
509
484
|
case "xml":
|
|
510
485
|
this.xml(file.key, file.url, file.overwrite);
|
|
511
486
|
break;
|
|
512
|
-
case "script":
|
|
513
|
-
this.script(file.key, file.url, file.callback, pack.callbackContext || this);
|
|
514
|
-
break;
|
|
515
|
-
case "binary":
|
|
516
|
-
this.binary(file.key, file.url, file.callback, pack.callbackContext || this);
|
|
517
|
-
break;
|
|
518
487
|
case "spritesheet":
|
|
519
488
|
this.spritesheet(file.key, file.url, file.frameWidth, file.frameHeight, file.frameMax, file.margin, file.spacing);
|
|
520
489
|
break;
|
|
@@ -527,23 +496,12 @@ export default class {
|
|
|
527
496
|
case "audioSprite":
|
|
528
497
|
this.audioSprite(file.key, file.audioURL, file.jsonURL, file.jsonData);
|
|
529
498
|
break;
|
|
530
|
-
case "tilemap":
|
|
531
|
-
// TODO
|
|
532
|
-
// this.tilemap(file.key, file.url, file.data, Phaser.Tilemap[file.format]);
|
|
533
|
-
break;
|
|
534
|
-
case "physics":
|
|
535
|
-
// TODO
|
|
536
|
-
// this.physics(file.key, file.url, file.data, Phaser.Loader[file.format]);
|
|
537
|
-
break;
|
|
538
499
|
case "bitmapFont":
|
|
539
500
|
this.bitmapFont(file.key, file.textureURL, file.atlasURL, file.atlasData, file.xSpacing, file.ySpacing);
|
|
540
501
|
break;
|
|
541
502
|
case "atlas":
|
|
542
503
|
this.atlas(file.key, file.textureURL, file.atlasURL, file.atlasData, TEXTURE_ATLAS_JSON_HASH);
|
|
543
504
|
break;
|
|
544
|
-
case "shader":
|
|
545
|
-
this.shader(file.key, file.url, file.overwrite);
|
|
546
|
-
break;
|
|
547
505
|
}
|
|
548
506
|
}
|
|
549
507
|
}
|
|
@@ -583,24 +541,9 @@ export default class {
|
|
|
583
541
|
case 'xml':
|
|
584
542
|
this.xhrLoad(file, this.transformUrl(file.url, file), 'text', this.xmlLoadComplete);
|
|
585
543
|
break;
|
|
586
|
-
case 'tilemap':
|
|
587
|
-
if (file.format === TILED_JSON) {
|
|
588
|
-
this.xhrLoad(file, this.transformUrl(file.url, file), 'text', this.jsonLoadComplete);
|
|
589
|
-
} else if (file.format === TILEMAP_CSV) {
|
|
590
|
-
this.xhrLoad(file, this.transformUrl(file.url, file), 'text', this.csvLoadComplete);
|
|
591
|
-
} else {
|
|
592
|
-
this.asyncComplete(file, 'invalid Tilemap format: ' + file.format);
|
|
593
|
-
}
|
|
594
|
-
break;
|
|
595
544
|
case 'text':
|
|
596
|
-
case 'script':
|
|
597
|
-
case 'shader':
|
|
598
|
-
case 'physics':
|
|
599
545
|
this.xhrLoad(file, this.transformUrl(file.url, file), 'text', this.fileComplete);
|
|
600
546
|
break;
|
|
601
|
-
case 'binary':
|
|
602
|
-
this.xhrLoad(file, this.transformUrl(file.url, file), 'arraybuffer', this.fileComplete);
|
|
603
|
-
break;
|
|
604
547
|
default:
|
|
605
548
|
// pass
|
|
606
549
|
break;
|
|
@@ -788,32 +731,6 @@ export default class {
|
|
|
788
731
|
file.data = xhr.responseText;
|
|
789
732
|
this.cache.addText(file.key, file.url, file.data);
|
|
790
733
|
break;
|
|
791
|
-
case 'shader':
|
|
792
|
-
file.data = xhr.responseText;
|
|
793
|
-
this.cache.addShader(file.key, file.url, file.data);
|
|
794
|
-
break;
|
|
795
|
-
case 'physics':
|
|
796
|
-
this.cache.addPhysicsData(file.key, file.url, JSON.parse(xhr.responseText), file.format);
|
|
797
|
-
break;
|
|
798
|
-
case 'script':
|
|
799
|
-
file.data = document.createElement('script');
|
|
800
|
-
file.data.language = 'javascript';
|
|
801
|
-
file.data.type = 'text/javascript';
|
|
802
|
-
file.data.defer = false;
|
|
803
|
-
file.data.text = xhr.responseText;
|
|
804
|
-
document.head.appendChild(file.data);
|
|
805
|
-
if (file.callback) {
|
|
806
|
-
file.data = file.callback.call(file.callbackContext, file.key, xhr.responseText);
|
|
807
|
-
}
|
|
808
|
-
break;
|
|
809
|
-
case 'binary':
|
|
810
|
-
if (file.callback) {
|
|
811
|
-
file.data = file.callback.call(file.callbackContext, file.key, xhr.response);
|
|
812
|
-
} else {
|
|
813
|
-
file.data = xhr.response;
|
|
814
|
-
}
|
|
815
|
-
this.cache.addBinary(file.key, file.data);
|
|
816
|
-
break;
|
|
817
734
|
default:
|
|
818
735
|
// pass
|
|
819
736
|
break;
|
|
@@ -825,9 +742,7 @@ export default class {
|
|
|
825
742
|
|
|
826
743
|
jsonLoadComplete(file, xhr) {
|
|
827
744
|
const data = JSON.parse(xhr.responseText);
|
|
828
|
-
if (file.type === '
|
|
829
|
-
this.cache.addTilemap(file.key, file.url, data, file.format);
|
|
830
|
-
} else if (file.type === 'bitmapfont') {
|
|
745
|
+
if (file.type === 'bitmapfont') {
|
|
831
746
|
this.cache.addBitmapFont(file.key, file.url, file.data, data, file.atlasType, file.xSpacing, file.ySpacing);
|
|
832
747
|
} else if (file.type === 'json') {
|
|
833
748
|
this.cache.addJSON(file.key, file.url, data);
|
package/src/phaser/core/raf.js
CHANGED
|
@@ -7,37 +7,21 @@ export default class {
|
|
|
7
7
|
|
|
8
8
|
constructor(game) {
|
|
9
9
|
this.game = game;
|
|
10
|
-
this.
|
|
11
|
-
this.timeoutId = null;
|
|
12
|
-
const vendors = [
|
|
13
|
-
'ms',
|
|
14
|
-
'moz',
|
|
15
|
-
'webkit',
|
|
16
|
-
'o',
|
|
17
|
-
];
|
|
18
|
-
for (let x = 0; x < vendors.length && !window.requestAnimationFrame; x += 1) {
|
|
19
|
-
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
|
|
20
|
-
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'];
|
|
21
|
-
}
|
|
10
|
+
this.rafId = 0;
|
|
22
11
|
this.updateBinded = this.update.bind(this);
|
|
23
12
|
}
|
|
24
13
|
|
|
25
14
|
start() {
|
|
26
|
-
this.
|
|
27
|
-
this.timeoutId = window.requestAnimationFrame(this.updateBinded);
|
|
15
|
+
this.rafId = requestAnimationFrame(this.updateBinded);
|
|
28
16
|
}
|
|
29
17
|
|
|
30
18
|
stop() {
|
|
31
|
-
|
|
32
|
-
this.isRunning = false;
|
|
19
|
+
cancelAnimationFrame(this.rafId);
|
|
33
20
|
}
|
|
34
21
|
|
|
35
22
|
update(rafTime) {
|
|
36
|
-
if (!this.isRunning) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
23
|
this.game.update(rafTime);
|
|
40
|
-
this.
|
|
24
|
+
this.rafId = requestAnimationFrame(this.updateBinded);
|
|
41
25
|
}
|
|
42
26
|
|
|
43
27
|
}
|