Skip to content

Commit 9651d4d

Browse files
committed
New Input Manager process event.
1 parent fb5882f commit 9651d4d

3 files changed

Lines changed: 73 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,42 @@
2121
* Fixed the `Leaderboard.getScores` method to now take the arguments into account. Fix #4271 (thanks @Oramy)
2222
* Fixed an API validation error in the `chooseContext` method. Fix #4248 (thanks @yadurajiv)
2323

24+
### Important Changes to the Input System
25+
26+
In Phaser 3.15 and earlier the Input system worked using an event queue. All native DOM input events, such as from the Mouse, Touch or Keyboard, were picked up by event handlers and stored in a queue within the Input Manager. This queue was then processed during the next game step, all the events were dealt with and then it was cleared, ready to receive more events. As they were processed, the internal Phaser events such as `pointerdown` or `keyup` were dispatched to your game code.
27+
28+
This worked fine in that you were able to guarantee _exactly_ when the events would arrive, because it was always at the same time in the game step. However, it had the side effect of you not being able to do things like open external browser windows, or go into Full Screen mode, during your event handlers - because they weren't "real" events, so didn't pass the browser security checks. To this end, methods like `addUpCallback` were added to try and provide this support (although it was never possible for keyboard events).
29+
30+
In 3.16 this has changed. The DOM Events now trigger the respective internal events immediately, in the same invocation. So if you click on the canvas, the `pointerdown` event you receive in your game is still part of the 'native' event handler, so you're now free to do things like go into full screen mode, or open external windows, without any browser warnings or work-arounds.
31+
32+
It does, however, mean that the point at which these handlers are called is no longer always consistent, and is no longer bound to the speed of the Request Animation Frame update. We've tested as much as possible, and so far, things carry on working as before. We've noticed a slight increase in responsiveness, due to the removal of the fractional delay in processing the events, which feels good. However, if for whatever reason this change has broken your game then you're able to easily switch back to the previous version. In your Game Config, create an `input` object and give it the property `queue: true`. This will tell Phaser to use the legacy event queue system.
33+
34+
Please note that we _will_ remove this legacy system in the near future. So, please try and adapt your games to use the new system. If you've found an edge-case where something breaks because of it, please report it so we can look into it.
35+
36+
As a result of this change, the following are now deprecated:
37+
38+
* `InputPlugin.addUpCallback` method.
39+
* `InputPlugin.addDownCallback` method.
40+
* `InputPlugin.addMoveCallback` method.
41+
* `InputManager.queue` property.
42+
* `InputManager.domCallbacks` property.
43+
* `InputManager._hasUpCallback` property.
44+
* `InputManager._hasDownCallback` property.
45+
* `InputManager._hasMoveCallback` property.
46+
* `InputManager.processDomCallbacks` method.
47+
* `InputManager.addUpCallback` method.
48+
* `InputManager.addDownCallback` method.
49+
* `InputManager.addMoveCallback` method.
50+
51+
### keydown and keyup changes
52+
53+
Due to unification across the event system, the `keydown_` and `keyup_` dynamic event strings have changed.
54+
55+
* In all cases the `keydown_KEY` event name has changed to `keydown-KEY`. Note the change from an underscore to a hyphen.
56+
* In all cases the `keyup_KEY` event name has changed to `keyup-KEY`. Note the change from an underscore to a hyphen.
57+
58+
You should update your game code accordingly.
59+
2460
### Keyboard Input - New Features
2561

2662
The specificity of the Keyboard events has been changed to allow you more control over event handling. Previously, the Keyboard Plugin would emit the global `keydown_CODE` event first (where CODE was a keycode string, like `keydown_A`), then it would emit the global `keydown` event. In previous versions, `Key` objects, created via `this.input.keyboard.addKey()`, didn't emit events.
@@ -126,7 +162,7 @@ one set of bindings ever created, which makes things a lot cleaner.
126162

127163
### Changes as a result of the new Scale Manager
128164

129-
* If you set the Game Config property `zoom` to be > 1 then it will automatically enable `pixelArt` mode, unless you set it to `false` in the config.
165+
* If you set the Game Config property `zoom` to be > 1 then it will automatically enable `pixelArt` mode, unless you set `pixelArt: false` in the config.
130166
* There is a new property in the Game Config called `autoRound`, which controls if the canvas size and style sizes are passed through Math.floor or not. On some devices this can help with performance and anti-aliasing. The default is `false` (turned off).
131167
* The Game Config property `autoResize` has been removed as it's now redundant.
132168
* The WebGL and Canvas Renderers no longer change the Canvas size in their `resize` methods. They just update internal properties.
@@ -138,6 +174,7 @@ one set of bindings ever created, which makes things a lot cleaner.
138174
* The `InputManager.transformY` method has been removed. This is now available in the ScaleManager.
139175
* The `InputManager.scale` property has been removed. This is now available in the ScaleManager under `displayScale`.
140176
* The `InputManager.resize` method has been removed as this process is now handled by the ScaleManager.
177+
* The `InputManager.bounds` property has been removed as this process is now handled by the ScaleManager.
141178
* The `InputManager.updateBounds` method has been removed as this process is now handled by the ScaleManager.
142179
* The `InputManager.getOffsetX` method has been removed as it's no longer required.
143180
* The `InputManager.getOffsetY` method has been removed as it's no longer required.
@@ -151,6 +188,22 @@ one set of bindings ever created, which makes things a lot cleaner.
151188
* The `Game.resize` method has been removed as it's no longer required. You should now call `ScaleManager.resize` instead.
152189
* The Game will no longer dispatch the `resize` event. You should now listen for this event from the Scale Manager instead.
153190

191+
### Important Namespace Changes
192+
193+
* The `Phaser.Boot` namespace has been renamed to `Phaser.Core`. As a result, the `boot` folder has been renamed to `core`. This impacts the `TimeStep` class and `VisibilityHandler` function, which have been moved to be under the new namespace.
194+
* The `Phaser.Animations` namespace was incorrectly exposed in the Phaser entrypoints as `Animation` (note the lack of plural). This means that if you are creating any custom classes that extend Animation objects using the Phaser namespace, then please update them from `Phaser.Animation` to `Phaser.Animations`, i.e. `Phaser.Animation.AnimationFrame` to `Phaser.Animations.AnimationFrame`. This doesn't impact you if you created animations directly via the Animation Manager.
195+
* The keyed Data Manager change data event string has changed from `changedata_` to `changedata-` to keep it consistent with other keyed events. Note the change from `_` to `-`.
196+
* The Keyboard Plugin `keydown` dynamic event string has changed from `keydown_` to `keydown-` to keep it consistent with other keyed events. Note the change from `_` to `-`.
197+
* The Keyboard Plugin `keyup` dynamic event string has changed from `keyup_` to `keyup-` to keep it consistent with other keyed events. Note the change from `_` to `-`.
198+
* The `texturesready` event emitted by the Texture Manager has been renamed to `ready`.
199+
* The `loadcomplete` event emitted by the Loader Plugin has been renamed to `postprocess` to be reflect what it's used for.
200+
* Game Objects used to emit a `collide` event if they had an Arcade Physics Body with `onCollide` set, that collided with a Tile. This has changed. The event has been renamed to `tilecollide` and you should now listen for this event from the Arcade Physics World itself: `this.physics.world.on('tilecollide')`. Game Objects no longer emit this event.
201+
* Game Objects used to emit an `overlap` event if they had an Arcade Physics Body with `onOverlap` set, that overlapped with a Tile. This has changed. The event has been renamed to `tileoverlap` and you should now listen for this event from the Arcade Physics World itself: `this.physics.world.on('tileoverlap')`. Game Objects no longer emit this event.
202+
* The function `Phaser.Physics.Impact.SeperateX` has been renamed to `SeparateX` to correct the spelling mistake.
203+
* The function `Phaser.Physics.Impact.SeperateY` has been renamed to `SeparateY` to correct the spelling mistake.
204+
* The `ended` event in `WebAudioSound` has been renamed to `complete` to make it more consistent with the rest of the API.
205+
* The `ended` event in `HTML5AudioSound` has been renamed to `complete` to make it more consistent with the rest of the API.
206+
154207
### New Features
155208

156209
* You can now load external Scene files using the new `load.sceneFile` method. This allows you to dynamically load a Scene into the Scene Manager of your game, and swap to it at will. Please see the documentation and examples for further details.
@@ -305,21 +358,6 @@ one set of bindings ever created, which makes things a lot cleaner.
305358
* Arcade Physics now manages when `postUpdate` should be applied better, stopping it from gaining a zero delta during a further check in the same frame. This fixes various issues, including the mass collision test demo. Fix #4154 (thanks @samme)
306359
* Arcade Physics could trigger a `collide` event on a Body even if it performing an overlap check, if the `onCollide` property was true (thanks @samme)
307360

308-
### Important Namespace Changes
309-
310-
* The `Phaser.Boot` namespace has been renamed to `Phaser.Core`. As a result, the `boot` folder has been renamed to `core`. This impacts the `TimeStep` class and `VisibilityHandler` function, which have been moved to be under the new namespace.
311-
* The `Phaser.Animations` namespace was incorrectly exposed in the Phaser entrypoints as `Animation` (note the lack of plural). This means that if you are creating any custom classes that extend Animation objects using the Phaser namespace, then please update them from `Phaser.Animation` to `Phaser.Animations`, i.e. `Phaser.Animation.AnimationFrame` to `Phaser.Animations.AnimationFrame`. This doesn't impact you if you created animations directly via the Animation Manager.
312-
* The keyed Data Manager change data event string has changed from `changedata_` to `changedata-` to keep it consistent with other keyed events. Note the change from `_` to `-`.
313-
* The Keyboard Plugin `keydown` dynamic event string has changed from `keydown_` to `keydown-` to keep it consistent with other keyed events. Note the change from `_` to `-`.
314-
* The Keyboard Plugin `keyup` dynamic event string has changed from `keyup_` to `keyup-` to keep it consistent with other keyed events. Note the change from `_` to `-`.
315-
* The `texturesready` event emitted by the Texture Manager has been renamed to `ready`.
316-
* The `loadcomplete` event emitted by the Loader Plugin has been renamed to `postprocess` to be reflect what it's used for.
317-
* Game Objects used to emit a `collide` event if they had an Arcade Physics Body with `onCollide` set, that collided with a Tile. This has changed. The event has been renamed to `tilecollide` and you should now listen for this event from the Arcade Physics World itself: `this.physics.world.on('tilecollide')`. Game Objects no longer emit this event.
318-
* Game Objects used to emit an `overlap` event if they had an Arcade Physics Body with `onOverlap` set, that overlapped with a Tile. This has changed. The event has been renamed to `tileoverlap` and you should now listen for this event from the Arcade Physics World itself: `this.physics.world.on('tileoverlap')`. Game Objects no longer emit this event.
319-
* The function `Phaser.Physics.Impact.SeperateX` has been renamed to `SeparateX` to correct the spelling mistake.
320-
* The function `Phaser.Physics.Impact.SeperateY` has been renamed to `SeparateY` to correct the spelling mistake.
321-
* The `ended` event in `WebAudioSound` has been renamed to `complete` to make it more consistent with the rest of the API.
322-
* The `ended` event in `HTML5AudioSound` has been renamed to `complete` to make it more consistent with the rest of the API.
323361

324362
### Examples and TypeScript
325363

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 Input Manager Process Event.
9+
*
10+
* This internal event is dispatched by the Input Manager when not using the legacy queue system,
11+
* and it wants the Input Plugins to update themselves.
12+
*
13+
* @event Phaser.Input.Events#MANAGER_PROCESS
14+
*
15+
* @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.
16+
* @param {number} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.
17+
*/
18+
module.exports = 'process';

src/input/events/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module.exports = {
3939
GAMEOBJECT_POINTER_UP: require('./GAMEOBJECT_POINTER_UP_EVENT'),
4040
GAMEOBJECT_UP: require('./GAMEOBJECT_UP_EVENT'),
4141
MANAGER_BOOT: require('./MANAGER_BOOT_EVENT'),
42+
MANAGER_PROCESS: require('./MANAGER_PROCESS_EVENT'),
4243
MANAGER_UPDATE: require('./MANAGER_UPDATE_EVENT'),
4344
POINTER_DOWN: require('./POINTER_DOWN_EVENT'),
4445
POINTER_DOWN_OUTSIDE: require('./POINTER_DOWN_OUTSIDE_EVENT'),

0 commit comments

Comments
 (0)