From 2acfbfbe7199ee7d430e2a55a7299ca1b0f1dae8 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Fri, 11 Sep 2020 14:01:55 +0100 Subject: [PATCH] `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 #4890. --- src/input/gamepad/Gamepad.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/input/gamepad/Gamepad.js b/src/input/gamepad/Gamepad.js index 52e8ae57c..7ca501848 100644 --- a/src/input/gamepad/Gamepad.js +++ b/src/input/gamepad/Gamepad.js @@ -313,6 +313,16 @@ var Gamepad = new Class({ * @since 3.10.0 */ this.rightStick = new Vector2(); + + /** + * When was this Gamepad created? Used to avoid duplicate event spamming in the update loop. + * + * @name Phaser.Input.Gamepad.Gamepad#_created + * @type {number} + * @private + * @since 3.50.0 + */ + this._created = performance.now(); }, /** @@ -420,6 +430,11 @@ var Gamepad = new Class({ */ update: function (pad) { + if (pad.timestamp < this._created) + { + return; + } + var i; // Sync the button values