@vpmedia/phaser 1.0.37 → 1.0.39

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.39",
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;
@@ -52,11 +51,9 @@ export default class {
52
51
  this.device = new Device();
53
52
  this.canvas = null;
54
53
  this.context = null;
55
- this.isStepping = false;
56
- this.isPendingStep = false;
57
- this.stepCount = 0;
58
- this.onPause = null;
59
- this.onResume = null;
54
+ this.onPause = new Signal();
55
+ this.onResume = new Signal();
56
+ this.onBoot = new Signal();
60
57
  this.isPaused = false;
61
58
  this.currentUpdateID = 0;
62
59
  this.updatesThisFrame = 1;
@@ -81,12 +78,9 @@ export default class {
81
78
 
82
79
  boot() {
83
80
  if (this.isBooted) {
84
- console.warn('Game already booted.');
85
81
  return;
86
82
  }
87
83
  this.isBooted = true;
88
- this.onPause = new Signal();
89
- this.onResume = new Signal();
90
84
  this.scale = new ScaleManager(this, this.config.width, this.config.height);
91
85
  this.stage = new Stage(this);
92
86
  this.initRenderer();
@@ -105,13 +99,15 @@ export default class {
105
99
  this.input.boot();
106
100
  this.sound.boot();
107
101
  this.state.boot();
108
- this.isRunning = true;
109
- this.raf = new RequestAnimationFrame(this);
110
102
  this.isKickStart = true;
111
103
  if (window.focus) {
112
104
  window.focus();
113
105
  }
114
- this.raf.start();
106
+ if (!this.config.isSkipTicker) {
107
+ this.raf = new RequestAnimationFrame(this);
108
+ this.raf.start();
109
+ }
110
+ this.onBoot.dispatch(this);
115
111
  }
116
112
 
117
113
  initRenderer() {
@@ -246,12 +242,6 @@ export default class {
246
242
  }
247
243
 
248
244
  update(time) {
249
- if (this.isPendingDestroy) {
250
- this.destroyDelayed();
251
- return;
252
- } else if (!this.isBooted) {
253
- return;
254
- }
255
245
  this.time.update(time);
256
246
  if (this.isKickStart) {
257
247
  this.updateLogic(this.time.desiredFpsMult);
@@ -260,7 +250,7 @@ export default class {
260
250
  this.isKickStart = false;
261
251
  return;
262
252
  }
263
- if (this._spiraling > 1 && !this.config.forceSingleUpdate) {
253
+ if (!this.config.forceSingleUpdate && this._spiraling > 1) {
264
254
  // cause an event to warn the program that this CPU can't keep up with the current desiredFps rate
265
255
  if (this.time.time > this._nextFpsNotification) {
266
256
  // only permit one fps notification per 10 seconds
@@ -310,10 +300,7 @@ export default class {
310
300
  }
311
301
 
312
302
  updateLogic(timeStep) {
313
- if (!this.isPaused && !this.isPendingStep) {
314
- if (this.isStepping) {
315
- this.isPendingStep = true;
316
- }
303
+ if (!this.isPaused) {
317
304
  this.scale.preUpdate();
318
305
  this.state.preUpdate(timeStep);
319
306
  this.stage.preUpdate();
@@ -337,44 +324,15 @@ export default class {
337
324
  this.state.render(elapsedTime);
338
325
  }
339
326
 
340
- enableStep() {
341
- this.isStepping = true;
342
- this.isPendingStep = false;
343
- this.stepCount = 0;
344
- }
345
-
346
- disableStep() {
347
- this.isStepping = false;
348
- this.isPendingStep = false;
349
- }
350
-
351
- step() {
352
- this.isPendingStep = false;
353
- this.stepCount += 1;
354
- }
355
-
356
327
  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
328
  this.isPaused = true;
370
- this.isBooted = false;
371
- this.isRunning = false;
372
329
 
373
- if (!this.raf) {
330
+ if (!this.cache) {
374
331
  return;
375
332
  }
376
-
377
- this.raf.stop();
333
+ if (this.raf) {
334
+ this.raf.stop();
335
+ }
378
336
 
379
337
  this.time.destroy();
380
338
  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
  }