@vpmedia/phaser 1.0.37 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vpmedia/phaser",
3
- "version": "1.0.37",
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",
@@ -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 = null;
59
- this.onResume = null;
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.raf.start();
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 && !this.config.forceSingleUpdate) {
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.raf) {
352
+ if (!this.cache) {
374
353
  return;
375
354
  }
376
-
377
- this.raf.stop();
355
+ if (this.raf) {
356
+ this.raf.stop();
357
+ }
378
358
 
379
359
  this.time.destroy();
380
360
  this.state.destroy();
@@ -7,37 +7,21 @@ export default class {
7
7
 
8
8
  constructor(game) {
9
9
  this.game = game;
10
- this.isRunning = false;
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.isRunning = true;
27
- this.timeoutId = window.requestAnimationFrame(this.updateBinded);
15
+ this.rafId = requestAnimationFrame(this.updateBinded);
28
16
  }
29
17
 
30
18
  stop() {
31
- window.cancelAnimationFrame(this.timeoutId);
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.timeoutId = window.requestAnimationFrame(this.updateBinded);
24
+ this.rafId = requestAnimationFrame(this.updateBinded);
41
25
  }
42
26
 
43
27
  }