Skip to content

Commit f29126c

Browse files
committed
KeyboardPlugin.resetKeys is a new method that will reset the state of any Key object created by a Scene's Keyboard Plugin.
1 parent b3804a2 commit f29126c

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

src/input/keyboard/KeyboardPlugin.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,18 +584,52 @@ var KeyboardPlugin = new Class({
584584
},
585585

586586
/**
587-
* Shuts the Keyboard Plugin down.
588-
* All this does is remove any listeners bound to it.
587+
* Resets all Key objects created by _this_ Keyboard Plugin back to their default un-pressed states.
588+
* This can only reset keys created via the `addKey`, `addKeys` or `createCursors` methods.
589+
* If you have created a Key object directly you'll need to reset it yourself.
590+
*
591+
* This method is called automatically when the Keyboard Plugin shuts down, but can be
592+
* invoked directly at any time you require.
593+
*
594+
* @method Phaser.Input.Keyboard.KeyboardPlugin#resetKeys
595+
* @since 3.15.0
596+
*/
597+
resetKeys: function ()
598+
{
599+
var keys = this.keys;
600+
601+
for (var i = 0; i < keys.length; i++)
602+
{
603+
// Because it's a sparsely populated array
604+
if (keys[i])
605+
{
606+
keys[i].reset();
607+
}
608+
}
609+
610+
return this;
611+
},
612+
613+
/**
614+
* Shuts this Keyboard Plugin down. This performs the following tasks:
615+
*
616+
* 1 - Resets all keys created by this Keyboard plugin.
617+
* 2 - Stops and removes the keyboard event listeners.
618+
* 3 - Clears out any pending requests in the queue, without processing them.
589619
*
590620
* @method Phaser.Input.Keyboard.KeyboardPlugin#shutdown
591621
* @private
592622
* @since 3.10.0
593623
*/
594624
shutdown: function ()
595625
{
626+
this.resetKeys();
627+
596628
this.stopListeners();
597629

598630
this.removeAllListeners();
631+
632+
this.queue = [];
599633
},
600634

601635
/**

0 commit comments

Comments
 (0)