The KeyboardPlugin.removeKey method has a new optional parameter removeCapture. This will remove any keyboard capture events for the given Key. Fix #5693

This commit is contained in:
Richard Davey 2021-11-01 18:13:51 +00:00
parent 841f0fc771
commit 3e1d77ad8f

View file

@ -547,12 +547,14 @@ var KeyboardPlugin = new Class({
*
* @param {(Phaser.Input.Keyboard.Key|string|number)} key - Either a Key object, a string, such as `A` or `SPACE`, or a key code value.
* @param {boolean} [destroy=false] - Call `Key.destroy` on the removed Key object?
* @param {boolean} [removeCapture=false] - Remove this Key from being captured? Only applies if set to capture when created.
*
* @return {this} This KeyboardPlugin object.
*/
removeKey: function (key, destroy)
removeKey: function (key, destroy, removeCapture)
{
if (destroy === undefined) { destroy = false; }
if (removeCapture === undefined) { removeCapture = false; }
var keys = this.keys;
var ref;
@ -584,6 +586,11 @@ var KeyboardPlugin = new Class({
{
ref.plugin = null;
if (removeCapture)
{
this.removeCapture(ref.keyCode);
}
if (destroy)
{
ref.destroy();
@ -600,11 +607,15 @@ var KeyboardPlugin = new Class({
* @since 3.24.0
*
* @param {boolean} [destroy=false] - Call `Key.destroy` on each removed Key object?
* @param {boolean} [removeCapture=false] - Remove all key captures for Key objects owened by this plugin?
*
* @return {this} This KeyboardPlugin object.
*/
removeAllKeys: function (destroy)
removeAllKeys: function (destroy, removeCapture)
{
if (destroy === undefined) { destroy = false; }
if (removeCapture === undefined) { removeCapture = false; }
var keys = this.keys;
for (var i = 0; i < keys.length; i++)
@ -615,6 +626,11 @@ var KeyboardPlugin = new Class({
{
keys[i] = undefined;
if (removeCapture)
{
this.removeCapture(key.keyCode);
}
if (destroy)
{
key.destroy();