2015-03-01 07:00:17 +00:00
|
|
|
/**
|
2015-03-23 23:27:14 +00:00
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2016-04-04 21:15:01 +00:00
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
2015-03-23 23:27:14 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The InputEnabled component allows a Game Object to have its own InputHandler and process input related events.
|
2015-03-01 07:00:17 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
*/
|
2015-02-17 05:15:04 +00:00
|
|
|
Phaser.Component.InputEnabled = function () {};
|
|
|
|
|
|
|
|
Phaser.Component.InputEnabled.prototype = {
|
|
|
|
|
|
|
|
/**
|
2015-03-23 23:27:14 +00:00
|
|
|
* The Input Handler for this Game Object.
|
|
|
|
*
|
|
|
|
* By default it is disabled. If you wish this Game Object to process input events you should enable it with: `inputEnabled = true`.
|
|
|
|
*
|
|
|
|
* After you have done this, this property will be a reference to the Phaser InputHandler.
|
|
|
|
* @property {Phaser.InputHandler|null} input
|
2015-02-17 05:15:04 +00:00
|
|
|
*/
|
|
|
|
input: null,
|
|
|
|
|
|
|
|
/**
|
2015-03-23 23:27:14 +00:00
|
|
|
* By default a Game Object won't process any input events. By setting `inputEnabled` to true a Phaser.InputHandler is created
|
|
|
|
* for this Game Object and it will then start to process click / touch events and more.
|
|
|
|
*
|
|
|
|
* You can then access the Input Handler via `this.input`.
|
|
|
|
*
|
|
|
|
* Note that Input related events are dispatched from `this.events`, i.e.: `events.onInputDown`.
|
|
|
|
*
|
|
|
|
* If you set this property to false it will stop the Input Handler from processing any more input events.
|
2016-06-22 23:45:24 +00:00
|
|
|
*
|
|
|
|
* If you want to _temporarily_ disable input for a Game Object, then it's better to set
|
|
|
|
* `input.enabled = false`, as it won't reset any of the Input Handlers internal properties.
|
|
|
|
* You can then toggle this back on as needed.
|
2015-02-17 05:15:04 +00:00
|
|
|
*
|
2015-03-23 23:27:14 +00:00
|
|
|
* @property {boolean} inputEnabled
|
2015-02-17 05:15:04 +00:00
|
|
|
*/
|
|
|
|
inputEnabled: {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return (this.input && this.input.enabled);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
if (this.input === null)
|
|
|
|
{
|
|
|
|
this.input = new Phaser.InputHandler(this);
|
|
|
|
this.input.start();
|
|
|
|
}
|
|
|
|
else if (this.input && !this.input.enabled)
|
|
|
|
{
|
|
|
|
this.input.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (this.input && this.input.enabled)
|
|
|
|
{
|
|
|
|
this.input.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|