Skip to content

Commit 680d34b

Browse files
committed
Convert Gamepad Manager to an Input Plugin
1 parent 0255498 commit 680d34b

4 files changed

Lines changed: 240 additions & 120 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ TODO - Out of Canvas events
2828
* Setting `enabled` to false on either the TouchManager, MouseManager or KeyboardManager will prevent it from handling any native DOM events until you set it back again.
2929
* InputPlugin has the following new read-only properties: `mousePointer`, `pointer1`, `pointer2`, `pointer3`, `pointer4`, `pointer5`, `pointer6`, `pointer7`, `pointer8`, `pointer9` and `pointer10`. Most of these will be undefined unless you call `addPointer` first, or set the active pointers quantity in your Game Config.
3030
* InputManager has a new method `transformPointer` which will set the transformed x and y properties of a Pointer in one call, rather than the 2 calls it took before. This is now used by all Pointer event handlers.
31+
32+
### Input - Keyboard Manager Updates
33+
3134
* The `KeyboardManager` class has been removed. It has been replaced with `KeyboardPlugin` which is now an Input level plugin, that registers itself with the new `InputPluginCache`. The Input Plugin class (which belongs to a Scene) will now automatically inject registered plugins into itself on boot. Every Scene has its own instance of the Input Plugin (if enabled in the scene plugins), which in turn has its own instance of the KeyboardPlugin. The `InputManager` no longer has any reference to the Keyboard class at all. The benefits of this are two-fold: First, it allows you to now entirely exclude all of the keyboard classes from a custom build, saving a lot of space if not required. Secondly, it means that the Scenes themselves are now responsible for keyboard events, where-as before they were entirely global. This means a Scene can be paused and stop processing keyboard events, and stop having its Key objects updated, while another Scene can still carry on doing this. It also prevents key related callbacks in sleeping Scenes from being fired (which resolves issue #3733, thanks @JoeMoov2)
3235
* `KeyboardManager.handler` has been renamed to `onKeyHandler`.
3336
* The `KeyboardManager.captures` property has been removed as it can be more effectively handled by polling the `keys` object instead.
@@ -38,6 +41,16 @@ TODO - Out of Canvas events
3841
* `KeyboardManager.addKey` can now take either a Key object, a string, such as `A` or `SPACE`, or a key code value.
3942
* `KeyboardManager.removeKey` can now take either a Key object, a string, such as `A` or `SPACE`, or a key code value.
4043

44+
### Input - Gamepad Manager Updates
45+
46+
* The `GamepadManager` class has been removed. It has been replaced with `GamepadPlugin` which is now an Input level plugin, that registers itself with the new `InputPluginCache`. The Input Plugin class (which belongs to a Scene) will now automatically inject the registered plugins into itself on boot. Every Scene has its own instance of the Input Plugin (if enabled in the scene plugins), which in turn has its own instance of the GamepadPlugin. The `InputManager` no longer has any reference to the Gamepad class at all. The benefits of this are two-fold: First, it allows you to now entirely exclude all of the gamepad classes from a custom build, saving a lot of space if not required. Secondly, it means that the Scenes themselves are now responsible for gamepad events, where-as before they were entirely global. This means a Scene can be paused and stop processing gamepad events, and stop having its Gamepad objects updated, while another Scene can still carry on doing this. It also prevents gamepad related callbacks in sleeping Scenes from being fired.
47+
* The Gamepad Plugin has been rewritten from scratch. It now offers a lot more features and far easier access to the Gamepads and their properties. You can now access the first 4 gamepads connected to the browser via the `pad1` to `pad4` properties, meaning you can do: `this.input.gamepad.pad1` for direct access to a pad once it's connected.
48+
* The Gamepad class has also been rewritten from scratch. It will no longer create Buttons or Axes dynamically, instead doing so on instantiation.
49+
* The Gamepad class now has a bunch of new properties for easy access to the various standard mapping buttons. These include `left`, `right`, `up`, `down` for directions, `A`, `Y`, `X` and `B` for buttons, `L1`, `L2`, `R1` and `R2` for shoulder buttons, and `leftStick` and `rightStick` for the axis sticks. You can still use `Gamepad.getButtonValue()` to get the value from a button and `Gamepad.getButtonTotal()` to get the total number of buttons available on the pad.
50+
* `Gamepad.getAxisTotal` and `Gamepad.getAxisValue` will return the total number of axis, and an axis value, accordingly.
51+
* `Gamepad.setAxisThreshold` will now let you set the threshold across all axis of a Gamepad in one call.
52+
* The Gamepad `Button` objects will now emit 2 events, one from the button itself and another from the Gamepad. This means you can listen for button events in 3 ways: 1) By directly polling the button value in an update loop, 2) Listening for events on the Gamepad Plugin: `this.input.gamepad.on('down')`, or 3) By listening for events on the Gamepad itself: `gamepadReference.on('down')`.
53+
4154
### Arcade Physics New Features + Updates
4255

4356
* Arcade Physics now uses a fixed time-step for all internal calculations. There is a new `fps` config value and property (defaults to 60fps), which you can change at run-time using the `setFPS` method. The core update loop has been recoded so that it steps based entirely on the given frame rate, and not the wall-clock or game step delta. This fixed time step allows for a straightforward implementation of a deterministic game state. Meaning you can now set the fps rate to a high value such as 240, regardless of the browser update speed (it will simply perform more physics steps per game step). This is handy if you want to increase the accuracy of the simulation in certain cases.

src/input/gamepad/Gamepad.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ var Vector2 = require('../../math/Vector2');
1414
* @classdesc
1515
* A single Gamepad.
1616
*
17-
* These are created, updated and managed by the Gamepad Manager.
17+
* These are created, updated and managed by the Gamepad Plugin.
1818
*
1919
* @class Gamepad
2020
* @extends Phaser.Events.EventEmitter
2121
* @memberOf Phaser.Input.Gamepad
2222
* @constructor
2323
* @since 3.0.0
2424
*
25-
* @param {Phaser.Input.Gamepad.GamepadManager} manager - A reference to the Gamepad Manager.
25+
* @param {Phaser.Input.Gamepad.GamepadPlugin} manager - A reference to the Gamepad Plugin.
2626
* @param {Pad} pad - The Gamepad object, as extracted from GamepadEvent.
2727
*/
2828
var Gamepad = new Class({
@@ -36,10 +36,10 @@ var Gamepad = new Class({
3636
EventEmitter.call(this);
3737

3838
/**
39-
* A reference to the Gamepad Manager.
39+
* A reference to the Gamepad Plugin.
4040
*
4141
* @name Phaser.Input.Gamepad.Gamepad#manager
42-
* @type {Phaser.Input.Gamepad.GamepadManager}
42+
* @type {Phaser.Input.Gamepad.GamepadPlugin}
4343
* @since 3.0.0
4444
*/
4545
this.manager = manager;

0 commit comments

Comments
 (0)