KeyboardPlugin.resetKeys is a new method that will reset the state of any Key object created by a Scene's Keyboard Plugin.

This commit is contained in:
Richard Davey 2018-10-16 11:35:44 +01:00
parent b3804a2455
commit f29126c482

View file

@ -584,8 +584,38 @@ var KeyboardPlugin = new Class({
},
/**
* Shuts the Keyboard Plugin down.
* All this does is remove any listeners bound to it.
* Resets all Key objects created by _this_ Keyboard Plugin back to their default un-pressed states.
* This can only reset keys created via the `addKey`, `addKeys` or `createCursors` methods.
* If you have created a Key object directly you'll need to reset it yourself.
*
* This method is called automatically when the Keyboard Plugin shuts down, but can be
* invoked directly at any time you require.
*
* @method Phaser.Input.Keyboard.KeyboardPlugin#resetKeys
* @since 3.15.0
*/
resetKeys: function ()
{
var keys = this.keys;
for (var i = 0; i < keys.length; i++)
{
// Because it's a sparsely populated array
if (keys[i])
{
keys[i].reset();
}
}
return this;
},
/**
* Shuts this Keyboard Plugin down. This performs the following tasks:
*
* 1 - Resets all keys created by this Keyboard plugin.
* 2 - Stops and removes the keyboard event listeners.
* 3 - Clears out any pending requests in the queue, without processing them.
*
* @method Phaser.Input.Keyboard.KeyboardPlugin#shutdown
* @private
@ -593,9 +623,13 @@ var KeyboardPlugin = new Class({
*/
shutdown: function ()
{
this.resetKeys();
this.stopListeners();
this.removeAllListeners();
this.queue = [];
},
/**