Skip to content

Commit 2acfbfb

Browse files
committed
Gamepad._created is a new private internal property that keeps track of when the instance was created. This is compared to the navigator timestamp in the update loop to avoid event spamming. Fix phaserjs#4890.
1 parent 5ecdc3b commit 2acfbfb

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/input/gamepad/Gamepad.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,16 @@ var Gamepad = new Class({
313313
* @since 3.10.0
314314
*/
315315
this.rightStick = new Vector2();
316+
317+
/**
318+
* When was this Gamepad created? Used to avoid duplicate event spamming in the update loop.
319+
*
320+
* @name Phaser.Input.Gamepad.Gamepad#_created
321+
* @type {number}
322+
* @private
323+
* @since 3.50.0
324+
*/
325+
this._created = performance.now();
316326
},
317327

318328
/**
@@ -420,6 +430,11 @@ var Gamepad = new Class({
420430
*/
421431
update: function (pad)
422432
{
433+
if (pad.timestamp < this._created)
434+
{
435+
return;
436+
}
437+
423438
var i;
424439

425440
// Sync the button values

0 commit comments

Comments
 (0)