mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 05:33:35 +00:00
The KeyboardPlugin
will now track the key code and timestamp of the previous key pressed and compare it to the current event. If they match, it will skip the event. On some systems if you were to type quickly, you would sometimes get duplicate key events firing (the exact same event firing more than once). This is now prevented from happening.
This commit is contained in:
parent
c4000843ec
commit
2810396dc7
1 changed files with 28 additions and 1 deletions
|
@ -146,7 +146,24 @@ var KeyboardPlugin = new Class({
|
|||
*/
|
||||
this.combos = [];
|
||||
|
||||
this.prevCode = 0;
|
||||
/**
|
||||
* Internal repeat key flag.
|
||||
*
|
||||
* @name Phaser.Input.Keyboard.KeyboardPlugin#prevCode
|
||||
* @type {string}
|
||||
* @private
|
||||
* @since 3.50.0
|
||||
*/
|
||||
this.prevCode = null;
|
||||
|
||||
/**
|
||||
* Internal repeat key flag.
|
||||
*
|
||||
* @name Phaser.Input.Keyboard.KeyboardPlugin#prevTime
|
||||
* @type {number}
|
||||
* @private
|
||||
* @since 3.50.0
|
||||
*/
|
||||
this.prevTime = 0;
|
||||
|
||||
sceneInputPlugin.pluginEvents.once(InputEvents.BOOT, this.boot, this);
|
||||
|
@ -725,6 +742,16 @@ var KeyboardPlugin = new Class({
|
|||
continue;
|
||||
}
|
||||
|
||||
// Duplicate event bailout
|
||||
if (code === this.prevCode && event.timeStamp === this.prevTime)
|
||||
{
|
||||
// On some systems, the exact same event will fire multiple times. This prevents it.
|
||||
continue;
|
||||
}
|
||||
|
||||
this.prevCode = code;
|
||||
this.prevTime = event.timeStamp;
|
||||
|
||||
if (event.type === 'keydown')
|
||||
{
|
||||
// Key specific callback first
|
||||
|
|
Loading…
Reference in a new issue