Skip to content

Commit 6fb2fd7

Browse files
committed
Adding the Scene Events.
1 parent 550c9bb commit 6fb2fd7

19 files changed

Lines changed: 413 additions & 13 deletions

src/scene/Systems.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
var Class = require('../utils/Class');
88
var CONST = require('./const');
99
var DefaultPlugins = require('../plugins/DefaultPlugins');
10+
var Events = require('./events');
1011
var GetPhysicsPlugins = require('./GetPhysicsPlugins');
1112
var GetScenePlugins = require('./GetScenePlugins');
1213
var NOOP = require('../utils/NOOP');
@@ -301,6 +302,7 @@ var Systems = new Class({
301302
*
302303
* @method Phaser.Scenes.Systems#init
303304
* @protected
305+
* @fires Phaser.Scenes.Events#BOOT
304306
* @since 3.0.0
305307
*
306308
* @param {Phaser.Game} game - A reference to the Phaser Game instance.
@@ -323,7 +325,7 @@ var Systems = new Class({
323325

324326
pluginManager.addToScene(this, DefaultPlugins.Global, [ DefaultPlugins.CoreScene, GetScenePlugins(this), GetPhysicsPlugins(this) ]);
325327

326-
this.events.emit('boot', this);
328+
this.events.emit(Events.BOOT, this);
327329

328330
this.settings.isBooted = true;
329331
},
@@ -352,27 +354,31 @@ var Systems = new Class({
352354
* Frame or Set Timeout call to the main Game instance.
353355
*
354356
* @method Phaser.Scenes.Systems#step
357+
* @fires Phaser.Scenes.Events#PRE_UPDATE
358+
* @fires Phaser.Scenes.Events#_UPDATE
359+
* @fires Phaser.Scenes.Events#POST_UPDATE
355360
* @since 3.0.0
356361
*
357362
* @param {number} time - The time value from the most recent Game step. Typically a high-resolution timer value, or Date.now().
358363
* @param {number} delta - The delta value since the last frame. This is smoothed to avoid delta spikes by the TimeStep class.
359364
*/
360365
step: function (time, delta)
361366
{
362-
this.events.emit('preupdate', time, delta);
367+
this.events.emit(Events.PRE_UPDATE, time, delta);
363368

364-
this.events.emit('update', time, delta);
369+
this.events.emit(Events.UPDATE, time, delta);
365370

366371
this.sceneUpdate.call(this.scene, time, delta);
367372

368-
this.events.emit('postupdate', time, delta);
373+
this.events.emit(Events.POST_UPDATE, time, delta);
369374
},
370375

371376
/**
372377
* Called automatically by the Scene Manager.
373378
* Instructs the Scene to render itself via its Camera Manager to the renderer given.
374379
*
375380
* @method Phaser.Scenes.Systems#render
381+
* @fires Phaser.Scenes.Events#RENDER
376382
* @since 3.0.0
377383
*
378384
* @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - The renderer that invoked the render call.
@@ -385,7 +391,7 @@ var Systems = new Class({
385391

386392
this.cameras.render(renderer, displayList);
387393

388-
this.events.emit('render', renderer);
394+
this.events.emit(Events.RENDER, renderer);
389395
},
390396

391397
/**
@@ -415,6 +421,7 @@ var Systems = new Class({
415421
* A paused Scene still renders, it just doesn't run ANY of its update handlers or systems.
416422
*
417423
* @method Phaser.Scenes.Systems#pause
424+
* @fires Phaser.Scenes.Events#PAUSE
418425
* @since 3.0.0
419426
*
420427
* @param {object} [data] - A data object that will be passed in the 'pause' event.
@@ -429,7 +436,7 @@ var Systems = new Class({
429436

430437
this.settings.active = false;
431438

432-
this.events.emit('pause', this, data);
439+
this.events.emit(Events.PAUSE, this, data);
433440
}
434441

435442
return this;
@@ -439,6 +446,7 @@ var Systems = new Class({
439446
* Resume this Scene from a paused state.
440447
*
441448
* @method Phaser.Scenes.Systems#resume
449+
* @fires Phaser.Scenes.Events#RESUME
442450
* @since 3.0.0
443451
*
444452
* @param {object} [data] - A data object that will be passed in the 'resume' event.
@@ -453,7 +461,7 @@ var Systems = new Class({
453461

454462
this.settings.active = true;
455463

456-
this.events.emit('resume', this, data);
464+
this.events.emit(Events.RESUME, this, data);
457465
}
458466

459467
return this;
@@ -468,6 +476,7 @@ var Systems = new Class({
468476
* from other Scenes may still invoke changes within it, so be careful what is left active.
469477
*
470478
* @method Phaser.Scenes.Systems#sleep
479+
* @fires Phaser.Scenes.Events#SLEEP
471480
* @since 3.0.0
472481
*
473482
* @param {object} [data] - A data object that will be passed in the 'sleep' event.
@@ -481,7 +490,7 @@ var Systems = new Class({
481490
this.settings.active = false;
482491
this.settings.visible = false;
483492

484-
this.events.emit('sleep', this, data);
493+
this.events.emit(Events.SLEEP, this, data);
485494

486495
return this;
487496
},
@@ -490,6 +499,7 @@ var Systems = new Class({
490499
* Wake-up this Scene if it was previously asleep.
491500
*
492501
* @method Phaser.Scenes.Systems#wake
502+
* @fires Phaser.Scenes.Events#WAKE
493503
* @since 3.0.0
494504
*
495505
* @param {object} [data] - A data object that will be passed in the 'wake' event.
@@ -505,7 +515,7 @@ var Systems = new Class({
505515
settings.active = true;
506516
settings.visible = true;
507517

508-
this.events.emit('wake', this, data);
518+
this.events.emit(Events.WAKE, this, data);
509519

510520
if (settings.isTransition)
511521
{
@@ -654,6 +664,8 @@ var Systems = new Class({
654664
* Called automatically by the SceneManager.
655665
*
656666
* @method Phaser.Scenes.Systems#start
667+
* @fires Phaser.Scenes.Events#START
668+
* @fires Phaser.Scenes.Events#READY
657669
* @since 3.0.0
658670
*
659671
* @param {object} data - Optional data object that may have been passed to this Scene from another.
@@ -671,10 +683,10 @@ var Systems = new Class({
671683
this.settings.visible = true;
672684

673685
// For plugins to listen out for
674-
this.events.emit('start', this);
686+
this.events.emit(Events.START, this);
675687

676688
// For user-land code to listen out for
677-
this.events.emit('ready', this, data);
689+
this.events.emit(Events.READY, this, data);
678690
},
679691

680692
/**
@@ -685,6 +697,7 @@ var Systems = new Class({
685697
* to free-up resources.
686698
*
687699
* @method Phaser.Scenes.Systems#shutdown
700+
* @fires Phaser.Scenes.Events#SHUTDOWN
688701
* @since 3.0.0
689702
*
690703
* @param {object} [data] - A data object that will be passed in the 'shutdown' event.
@@ -701,7 +714,7 @@ var Systems = new Class({
701714
this.settings.active = false;
702715
this.settings.visible = false;
703716

704-
this.events.emit('shutdown', this, data);
717+
this.events.emit(Events.SHUTDOWN, this, data);
705718
},
706719

707720
/**
@@ -711,6 +724,7 @@ var Systems = new Class({
711724
*
712725
* @method Phaser.Scenes.Systems#destroy
713726
* @private
727+
* @fires Phaser.Scenes.Events#DESTROY
714728
* @since 3.0.0
715729
*/
716730
destroy: function ()
@@ -720,7 +734,7 @@ var Systems = new Class({
720734
this.settings.active = false;
721735
this.settings.visible = false;
722736

723-
this.events.emit('destroy', this);
737+
this.events.emit(Events.DESTROY, this);
724738

725739
this.events.removeAllListeners();
726740

src/scene/events/BOOT_EVENT.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Scene Systems Boot Event.
9+
*
10+
* This event is dispatched by a Scene during the Scene Systems boot process. Primarily used by Scene Plugins.
11+
*
12+
* Listen to it from a Scene using `this.scene.events.on('boot', listener)`.
13+
*
14+
* @event Phaser.Scenes.Events#BOOT
15+
*
16+
* @param {Phaser.Scenes.Systems} sys - A reference to the Scene Systems class of the Scene that emitted this event.
17+
*/
18+
module.exports = 'boot';

src/scene/events/DESTROY_EVENT.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Scene Systems Destroy Event.
9+
*
10+
* This event is dispatched by a Scene during the Scene Systems destroy process.
11+
*
12+
* Listen to it from a Scene using `this.scene.events.on('destroy', listener)`.
13+
*
14+
* You should destroy any resources that may be in use by your Scene in this event handler.
15+
*
16+
* @event Phaser.Scenes.Events#DESTROY
17+
*
18+
* @param {Phaser.Scenes.Systems} sys - A reference to the Scene Systems class of the Scene that emitted this event.
19+
*/
20+
module.exports = 'destroy';

src/scene/events/PAUSE_EVENT.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Scene Systems Pause Event.
9+
*
10+
* This event is dispatched by a Scene when it is paused, either directly via the `pause` method, or as an
11+
* action from another Scene.
12+
*
13+
* Listen to it from a Scene using `this.scene.events.on('pause', listener)`.
14+
*
15+
* @event Phaser.Scenes.Events#PAUSE
16+
*
17+
* @param {Phaser.Scenes.Systems} sys - A reference to the Scene Systems class of the Scene that emitted this event.
18+
* @param {any} [data] - An optional data object that was passed to this Scene when it was paused.
19+
*/
20+
module.exports = 'pause';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Scene Systems Post Update Event.
9+
*
10+
* This event is dispatched by a Scene during the main game loop step.
11+
*
12+
* The event flow for a single step of a Scene is as follows:
13+
*
14+
* 1) [PRE_UPDATE]{Phaser.Scenes.Events#PRE_UPDATE}
15+
* 2) [UPDATE]{Phaser.Scenes.Events#UPDATE}
16+
* 3) The Scene.update method is called, if it exists
17+
* 4) [POST_UPDATE]{Phaser.Scenes.Events#POST_UPDATE}
18+
* 5) [RENDER]{Phaser.Scenes.Events#RENDER}
19+
*
20+
* Listen to it from a Scene using `this.scene.events.on('postupdate', listener)`.
21+
*
22+
* A Scene will only run its step if it is active.
23+
*
24+
* @event Phaser.Scenes.Events#POST_UPDATE
25+
*
26+
* @param {Phaser.Scenes.Systems} sys - A reference to the Scene Systems class of the Scene that emitted this event.
27+
* @param {number} time - The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.
28+
* @param {number} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.
29+
*/
30+
module.exports = 'postupdate';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Scene Systems Pre Update Event.
9+
*
10+
* This event is dispatched by a Scene during the main game loop step.
11+
*
12+
* The event flow for a single step of a Scene is as follows:
13+
*
14+
* 1) [PRE_UPDATE]{Phaser.Scenes.Events#PRE_UPDATE}
15+
* 2) [UPDATE]{Phaser.Scenes.Events#UPDATE}
16+
* 3) The Scene.update method is called, if it exists
17+
* 4) [POST_UPDATE]{Phaser.Scenes.Events#POST_UPDATE}
18+
* 5) [RENDER]{Phaser.Scenes.Events#RENDER}
19+
*
20+
* Listen to it from a Scene using `this.scene.events.on('preupdate', listener)`.
21+
*
22+
* A Scene will only run its step if it is active.
23+
*
24+
* @event Phaser.Scenes.Events#PRE_UPDATE
25+
*
26+
* @param {Phaser.Scenes.Systems} sys - A reference to the Scene Systems class of the Scene that emitted this event.
27+
* @param {number} time - The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.
28+
* @param {number} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.
29+
*/
30+
module.exports = 'preupdate';

src/scene/events/READY_EVENT.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Scene Systems Ready Event.
9+
*
10+
* This event is dispatched by a Scene during the Scene Systems start process.
11+
* By this point in the process the Scene is now fully active and rendering.
12+
* This event is meant for your game code to use, as all plugins have responded to the earlier 'start' event.
13+
*
14+
* Listen to it from a Scene using `this.scene.events.on('ready', listener)`.
15+
*
16+
* @event Phaser.Scenes.Events#READY
17+
*
18+
* @param {Phaser.Scenes.Systems} sys - A reference to the Scene Systems class of the Scene that emitted this event.
19+
* @param {any} [data] - An optional data object that was passed to this Scene when it was started.
20+
*/
21+
module.exports = 'ready';

src/scene/events/RENDER_EVENT.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Scene Systems Render Event.
9+
*
10+
* This event is dispatched by a Scene during the main game loop step.
11+
*
12+
* The event flow for a single step of a Scene is as follows:
13+
*
14+
* 1) [PRE_UPDATE]{Phaser.Scenes.Events#PRE_UPDATE}
15+
* 2) [UPDATE]{Phaser.Scenes.Events#UPDATE}
16+
* 3) The Scene.update method is called, if it exists
17+
* 4) [POST_UPDATE]{Phaser.Scenes.Events#POST_UPDATE}
18+
* 5) [RENDER]{Phaser.Scenes.Events#RENDER}
19+
*
20+
* Listen to it from a Scene using `this.scene.events.on('render', listener)`.
21+
*
22+
* A Scene will only render if it is visible and active.
23+
* By the time this event is dispatched, the Scene will have already been rendered.
24+
*
25+
* @event Phaser.Scenes.Events#RENDER
26+
*
27+
* @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - The renderer that rendered the Scene.
28+
*/
29+
module.exports = 'render';

src/scene/events/RESUME_EVENT.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Scene Systems Resume Event.
9+
*
10+
* This event is dispatched by a Scene when it is resumed from a paused state, either directly via the `resume` method,
11+
* or as an action from another Scene.
12+
*
13+
* Listen to it from a Scene using `this.scene.events.on('resume', listener)`.
14+
*
15+
* @event Phaser.Scenes.Events#RESUME
16+
*
17+
* @param {Phaser.Scenes.Systems} sys - A reference to the Scene Systems class of the Scene that emitted this event.
18+
* @param {any} [data] - An optional data object that was passed to this Scene when it was resumed.
19+
*/
20+
module.exports = 'resume';

0 commit comments

Comments
 (0)