Skip to content

Commit 5ecdc3b

Browse files
committed
The GamepadPlugin will now call refreshPads as part of its start process. This allows you to use Gamepads across multiple Scenes, without having to wait for a connected event from each one of them. If you've already had a connected event in a previous Scene, you can now just read the pads directly via this.input.gamepad.pad1 and similar. Fix phaserjs#4890
1 parent a54a3a3 commit 5ecdc3b

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/input/gamepad/GamepadPlugin.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ var InputEvents = require('../events');
4040
* to the gamepads you can poll its buttons and axis sticks. See the properties and methods available on
4141
* the `Gamepad` class for more details.
4242
*
43+
* As of September 2020 Chrome, and likely other browsers, will soon start to require that games requesting
44+
* access to the Gamepad API are running under SSL. They will actively block API access if they are not.
45+
*
4346
* For more information about Gamepad support in browsers see the following resources:
4447
*
4548
* https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API
@@ -221,6 +224,8 @@ var GamepadPlugin = new Class({
221224
if (this.enabled)
222225
{
223226
this.startListeners();
227+
228+
this.refreshPads();
224229
}
225230

226231
this.sceneInputPlugin.pluginEvents.once(InputEvents.SHUTDOWN, this.shutdown, this);
@@ -292,6 +297,11 @@ var GamepadPlugin = new Class({
292297
this.target.removeEventListener('gamepaddisconnected', this.onGamepadHandler);
293298

294299
this.sceneInputPlugin.pluginEvents.off(InputEvents.UPDATE, this.update);
300+
301+
for (var i = 0; i < this.gamepads.length; i++)
302+
{
303+
this.gamepads[i].removeAllListeners();
304+
}
295305
},
296306

297307
/**
@@ -304,7 +314,7 @@ var GamepadPlugin = new Class({
304314
{
305315
for (var i = 0; i < this.gamepads.length; i++)
306316
{
307-
this.gamepads.connected = false;
317+
this.gamepads[i].pad.connected = false;
308318
}
309319
},
310320

@@ -489,8 +499,6 @@ var GamepadPlugin = new Class({
489499
{
490500
this.stopListeners();
491501

492-
this.disconnectAll();
493-
494502
this.removeAllListeners();
495503
},
496504

0 commit comments

Comments
 (0)