InputManager.resetLocked - If the Input Manager has been reset locked then all calls made to InputManager.reset, such as from a State change, are ignored.

Keyboard.reset has a new `hard` parameter which controls the severity of the reset. A soft reset doesn't remove any callbacks or event listeners.
Key.reset has a new `hard` parameter which controls the severity of the reset. A soft reset doesn't remove any callbacks or event listeners.
This commit is contained in:
photonstorm 2014-04-14 21:53:08 +01:00
parent 055cb8058d
commit a7f6165e39
4 changed files with 36 additions and 13 deletions

View file

@ -61,6 +61,7 @@ Version 2.0.4 - "Mos Shirare" - in development
* TypeScript definitions fixes and updates (thanks @clark-stevenson)
* Timer has removed all use of local temporary vars in the core update loop.
* The Input.reset `hard` reset parameter is now passed down to the Keyboard and Key reset methods.
### New Features
@ -68,6 +69,10 @@ Version 2.0.4 - "Mos Shirare" - in development
* Loader now has an onFileStart event you can listen for (thanks @codevinsky, #705)
* Timer.clearPendingEvents will purge any events marked for deletion, this is run automatically at the start of the update loop.
* Device.crosswalk detects if your game is running under Intels Crosswalk XDK.
* Keyboard.reset has a new `hard` parameter which controls the severity of the reset. A soft reset doesn't remove any callbacks or event listeners.
* Key.reset has a new `hard` parameter which controls the severity of the reset. A soft reset doesn't remove any callbacks or event listeners.
* InputManager.resetLocked - If the Input Manager has been reset locked then all calls made to InputManager.reset, such as from a State change, are ignored.
### Bug Fixes

View file

@ -241,6 +241,12 @@ Phaser.Input = function (game) {
*/
// this.gestures = null;
/**
* @property {boolean} resetLocked - If the Input Manager has been reset locked then all calls made to InputManager.reset, such as from a State change, are ignored.
* @default
*/
this.resetLocked = false;
/**
* @property {Phaser.Signal} onDown - A Signal that is dispatched each time a pointer is pressed down.
*/
@ -470,20 +476,23 @@ Phaser.Input.prototype = {
},
/**
* Reset all of the Pointers and Input states
* Reset all of the Pointers and Input states. The optional `hard` parameter will reset any events or callbacks that may be bound.
* Input.reset is called automatically during a State change or if a game loses focus / visibility. If you wish to control the reset
* directly yourself then set InputManager.resetLocked to `true`.
*
* @method Phaser.Input#reset
* @param {boolean} hard - A soft reset (hard = false) won't reset any Signals that might be bound. A hard reset will.
* @param {boolean} [hard=false] - A soft reset won't reset any events or callbacks that are bound. A hard reset will.
*/
reset: function (hard) {
if (this.game.isBooted === false)
if (!this.game.isBooted || this.resetLocked)
{
return;
}
if (typeof hard == 'undefined') { hard = false; }
if (typeof hard === 'undefined') { hard = false; }
this.keyboard.reset();
this.keyboard.reset(hard);
this.mousePointer.reset();
this.gamepad.reset();
@ -502,7 +511,7 @@ Phaser.Input.prototype = {
this.game.canvas.style.cursor = 'inherit';
}
if (hard === true)
if (hard)
{
this.onDown.dispose();
this.onUp.dispose();

View file

@ -193,8 +193,11 @@ Phaser.Key.prototype = {
* associated with the onDown and onUp events and nulls the onHoldCallback if set.
*
* @method Phaser.Key#reset
* @param {boolean} [hard=true] - A soft reset won't reset any events or callbacks that are bound to this Key. A hard reset will.
*/
reset: function () {
reset: function (hard) {
if (typeof hard === 'undefined') { hard = true; }
this.isDown = false;
this.isUp = true;
@ -202,10 +205,13 @@ Phaser.Key.prototype = {
this.duration = this.game.time.now - this.timeDown;
this.enabled = true;
if (hard)
{
this.onDown.removeAll();
this.onUp.removeAll();
this.onHoldCallback = null;
this.onHoldContext = null;
}
},

View file

@ -358,8 +358,11 @@ Phaser.Keyboard.prototype = {
* Resets all Keys.
*
* @method Phaser.Keyboard#reset
* @param {boolean} [hard=true] - A soft reset won't reset any events or callbacks that are bound to the Keys. A hard reset will.
*/
reset: function () {
reset: function (hard) {
if (typeof hard === 'undefined') { hard = true; }
this.event = null;
@ -369,7 +372,7 @@ Phaser.Keyboard.prototype = {
{
if (this._keys[i])
{
this._keys[i].reset();
this._keys[i].reset(hard);
}
}