mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 14:38:30 +00:00
Key now needs a reference to the plugin that created it. Also added getDuration
method.
This commit is contained in:
parent
d7917789eb
commit
6b5383a007
1 changed files with 40 additions and 1 deletions
|
@ -19,6 +19,7 @@ var Events = require('../events');
|
||||||
* @constructor
|
* @constructor
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*
|
*
|
||||||
|
* @param {Phaser.Input.Keyboard.KeyboardPlugin} plugin - The Keyboard Plugin instance that owns this Key object.
|
||||||
* @param {integer} keyCode - The keycode of this key.
|
* @param {integer} keyCode - The keycode of this key.
|
||||||
*/
|
*/
|
||||||
var Key = new Class({
|
var Key = new Class({
|
||||||
|
@ -27,10 +28,19 @@ var Key = new Class({
|
||||||
|
|
||||||
initialize:
|
initialize:
|
||||||
|
|
||||||
function Key (keyCode)
|
function Key (plugin, keyCode)
|
||||||
{
|
{
|
||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Keyboard Plugin instance that owns this Key object.
|
||||||
|
*
|
||||||
|
* @name Phaser.Input.Keyboard.Key#plugin
|
||||||
|
* @type {Phaser.Input.Keyboard.KeyboardPlugin}
|
||||||
|
* @since 3.17.0
|
||||||
|
*/
|
||||||
|
this.plugin = plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The keycode of this key.
|
* The keycode of this key.
|
||||||
*
|
*
|
||||||
|
@ -142,6 +152,8 @@ var Key = new Class({
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of milliseconds this key was held down for in the previous down - up sequence.
|
* The number of milliseconds this key was held down for in the previous down - up sequence.
|
||||||
|
* This value isn't updated every game step, only when the Key changes state.
|
||||||
|
* To get the current duration use the `getDuration` method.
|
||||||
*
|
*
|
||||||
* @name Phaser.Input.Keyboard.Key#duration
|
* @name Phaser.Input.Keyboard.Key#duration
|
||||||
* @type {number}
|
* @type {number}
|
||||||
|
@ -339,6 +351,31 @@ var Key = new Class({
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the duration, in ms, that the Key has been held down for.
|
||||||
|
*
|
||||||
|
* If the key is not currently down it will return zero.
|
||||||
|
*
|
||||||
|
* The get the duration the Key was held down for in the previous up-down cycle,
|
||||||
|
* use the `Key.duration` property value instead.
|
||||||
|
*
|
||||||
|
* @method Phaser.Input.Keyboard.Key#getDuration
|
||||||
|
* @since 3.17.0
|
||||||
|
*
|
||||||
|
* @return {integer} The duration, in ms, that the Key has been held down for if currently down.
|
||||||
|
*/
|
||||||
|
getDuration: function ()
|
||||||
|
{
|
||||||
|
if (this.isDown)
|
||||||
|
{
|
||||||
|
return (this.plugin.game.loop.time - this.timeDown);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes any bound event handlers and removes local references.
|
* Removes any bound event handlers and removes local references.
|
||||||
*
|
*
|
||||||
|
@ -350,6 +387,8 @@ var Key = new Class({
|
||||||
this.removeAllListeners();
|
this.removeAllListeners();
|
||||||
|
|
||||||
this.originalEvent = null;
|
this.originalEvent = null;
|
||||||
|
|
||||||
|
this.plugin = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue