diff --git a/src/input/keyboard/KeyboardPlugin.js b/src/input/keyboard/KeyboardPlugin.js index 4f7163a78..2f8d19a89 100644 --- a/src/input/keyboard/KeyboardPlugin.js +++ b/src/input/keyboard/KeyboardPlugin.js @@ -566,6 +566,38 @@ var KeyboardPlugin = new Class({ return this; }, + /** + * Removes all Key objects created by _this_ Keyboard Plugin. + * + * @method Phaser.Input.Keyboard.KeyboardPlugin#removeAllKeys + * @since 3.24.0 + * + * @param {boolean} [destroy=false] - Call `Key.destroy` on each removed Key object? + * + * @return {this} This KeyboardPlugin object. + */ + removeAllKeys: function (destroy) + { + var keys = this.keys; + + for (var i = 0; i < keys.length; i++) + { + var key = keys[i]; + + if (key) + { + keys[i] = undefined; + + if (destroy) + { + key.destroy(); + } + } + } + + return this; + }, + /** * Creates a new KeyCombo. *