Skip to content

Commit f3f65d1

Browse files
committed
Refactored the game over and out handling to work with the non-legacy input system. Fix phaserjs#4344
1 parent a252225 commit f3f65d1

3 files changed

Lines changed: 43 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The following changes all effect the Matter JS Pointer Constraint class:
3636
* The `Mesh.setAlpha` method has been restored, even though it's empty and does nothing, to prevent runtime errors when adding a Mesh or Quad object to a Container. Fix #4338 #4343 (thanks @pfdtravalmatic @charmingny)
3737
* `KeyboardPlugin.checkDown` would always fail if using the new event system, because the time value it was checking wasn't updated.
3838
* Entering Fullscreen mode in the Scale Manager and then pressing ESC would leave the injected fullsceen div in the DOM, causing it to fail with a node insertion failure the second time you wanted to enter fullscreen mode. Fix #4352 (thanks @ngdevr)
39-
39+
* Due to the changes in the Input event system, the `GAME_OUT` event would never fire unless the input system was in legacy mode. The OUT and OVER handlers have been refactored and will now fire as soon as the DOM event happens. As a result the `InputManager._emitIsOverEvent` property has been removed, as the native event is sent directly to the handler and doesn't need storing locally any more. Fix #4344 (thanks @RademCZ)
4040

4141
### Examples, Documentation and TypeScript
4242

src/input/InputManager.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,6 @@ var InputManager = new Class({
135135
*/
136136
this.isOver = true;
137137

138-
/**
139-
* The DOM Event that was fired when the canvas dispatched an over or out event.
140-
*
141-
* @name Phaser.Input.InputManager#_emitIsOverEvent
142-
* @type {(MouseEvent|TouchEvent)}
143-
* @private
144-
* @since 3.16.0
145-
*/
146-
this._emitIsOverEvent = false;
147-
148138
/**
149139
* Are there any up callbacks defined?
150140
*
@@ -456,6 +446,7 @@ var InputManager = new Class({
456446
* Internal canvas state change, called automatically by the Mouse Manager.
457447
*
458448
* @method Phaser.Input.InputManager#setCanvasOver
449+
* @fires Phaser.Input.Events#GAME_OVER
459450
* @private
460451
* @since 3.16.0
461452
*
@@ -465,13 +456,14 @@ var InputManager = new Class({
465456
{
466457
this.isOver = true;
467458

468-
this._emitIsOverEvent = event;
459+
this.events.emit(Events.GAME_OVER, event);
469460
},
470461

471462
/**
472463
* Internal canvas state change, called automatically by the Mouse Manager.
473464
*
474465
* @method Phaser.Input.InputManager#setCanvasOut
466+
* @fires Phaser.Input.Events#GAME_OUT
475467
* @private
476468
* @since 3.16.0
477469
*
@@ -481,7 +473,7 @@ var InputManager = new Class({
481473
{
482474
this.isOver = false;
483475

484-
this._emitIsOverEvent = event;
476+
this.events.emit(Events.GAME_OUT, event);
485477
},
486478

487479
/**
@@ -647,9 +639,6 @@ var InputManager = new Class({
647639
this.canvas.style.cursor = this.defaultCursor;
648640
}
649641

650-
// Reset the isOver event
651-
this._emitIsOverEvent = null;
652-
653642
this.dirty = false;
654643

655644
this._updatedThisFrame = false;

src/input/InputPlugin.js

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ var InputPlugin = new Class({
407407

408408
eventEmitter.once(SceneEvents.SHUTDOWN, this.shutdown, this);
409409

410+
this.manager.events.on(Events.GAME_OUT, this.onGameOut, this);
411+
this.manager.events.on(Events.GAME_OVER, this.onGameOver, this);
412+
410413
this.enabled = true;
411414

412415
// Populate the pointer drag states
@@ -416,6 +419,38 @@ var InputPlugin = new Class({
416419
this.pluginEvents.emit(Events.START);
417420
},
418421

422+
/**
423+
* Game Over handler.
424+
*
425+
* @method Phaser.Input.InputPlugin#onGameOver
426+
* @fires Phaser.Input.Events#GAME_OVER
427+
* @private
428+
* @since 3.16.2
429+
*/
430+
onGameOver: function (event)
431+
{
432+
if (this.isActive())
433+
{
434+
this.emit(Events.GAME_OVER, event.timeStamp, event);
435+
}
436+
},
437+
438+
/**
439+
* Game Out handler.
440+
*
441+
* @method Phaser.Input.InputPlugin#onGameOut
442+
* @fires Phaser.Input.Events#GAME_OUT
443+
* @private
444+
* @since 3.16.2
445+
*/
446+
onGameOut: function (event)
447+
{
448+
if (this.isActive())
449+
{
450+
this.emit(Events.GAME_OUT, event.timeStamp, event);
451+
}
452+
},
453+
419454
/**
420455
* The pre-update handler is responsible for checking the pending removal and insertion lists and
421456
* deleting old Game Objects.
@@ -485,8 +520,6 @@ var InputPlugin = new Class({
485520
* Called automatically by the Scene Systems step.
486521
*
487522
* @method Phaser.Input.InputPlugin#update
488-
* @fires Phaser.Input.Events#GAME_OUT
489-
* @fires Phaser.Input.Events#GAME_OVER
490523
* @fires Phaser.Input.Events#UPDATE
491524
* @private
492525
* @since 3.0.0
@@ -511,13 +544,6 @@ var InputPlugin = new Class({
511544
return;
512545
}
513546

514-
if (manager._emitIsOverEvent)
515-
{
516-
var event = (manager.isOver) ? Events.GAME_OVER : Events.GAME_OUT;
517-
518-
this.emit(event, time, manager._emitIsOverEvent);
519-
}
520-
521547
var runUpdate = (manager.dirty || this.pollRate === 0);
522548

523549
if (this.pollRate > -1)
@@ -2356,6 +2382,9 @@ var InputPlugin = new Class({
23562382
eventEmitter.off(SceneEvents.UPDATE, this.update, this);
23572383
}
23582384

2385+
this.manager.events.off(Events.GAME_OUT, this.onGameOut, this);
2386+
this.manager.events.off(Events.GAME_OVER, this.onGameOver, this);
2387+
23592388
eventEmitter.off(SceneEvents.SHUTDOWN, this.shutdown, this);
23602389
},
23612390

0 commit comments

Comments
 (0)