Skip to content

Commit 672a535

Browse files
committed
Added disableInteractive and removeInteractive methods. phaserjs#3621
1 parent 0441e19 commit 672a535

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Change Log
22

3-
## Version 3.7.0 - Sinon - in development
3+
## Version 3.7.0 - Sinon - 8th May 2018
44

55
### New Features
66

@@ -9,6 +9,8 @@
99
* CanvasTexture is a new extension of the Texture object specifically created for when you've got a Canvas element as the backing source of the texture that you wish to draw to programmatically using the Canvas API. This was possible in previous versions, as a Texture object supported having a Canvas as its source, but we've streamlined the process and made it a lot easier for you to refresh the resulting WebGLTexture on the GPU. To create a CanvasTexture just call the `TextureManager.createCanvas` method as before, only this time you'll get a CanvasTexture back which has helper properties and methods. See the complete JSDocs for more details.
1010
* RandomDataGenerator has a new method: `shuffle` which allows you to shuffle an array using the current RNG seed (thanks @wtravO)
1111
* The Texture Manager now supports normal maps for Atlas JSON (in both hash and array formats), Atlas XML and Atlas Unity.
12+
* All Game Objects have a new method `disableInteractive` which will disable the Interactive Object bound to them. You can toggle it back again by calling `setInteractive` with no arguments.
13+
* All Game Objects have a new method `removeInteractive` which will destroy the Interactive Object bound to them entirely. Use this if a Game Object no longer needs any input at all but you don't want to destroy the Game Object itself.
1214

1315
### Loader New Features and Important Updates
1416

src/gameobjects/GameObject.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,57 @@ var GameObject = new Class({
291291
return this;
292292
},
293293

294+
/**
295+
* If this Game Object has previously been enabled for input, this will disable it.
296+
*
297+
* An object that is disabled for input stops processing or being considered for
298+
* input events, but can be turned back on again at any time by simply calling
299+
* `setInteractive()` with no arguments provided.
300+
*
301+
* If want to completely remove interaction from this Game Object then use `removeInteractive` instead.
302+
*
303+
* @method Phaser.GameObjects.GameObject#disableInteractive
304+
* @since 3.7.0
305+
*
306+
* @return {Phaser.GameObjects.GameObject} This GameObject.
307+
*/
308+
disableInteractive: function ()
309+
{
310+
if (this.input)
311+
{
312+
this.input.enabled = (this.input.enabled) ? false : true;
313+
}
314+
315+
return this;
316+
},
317+
318+
/**
319+
* If this Game Object has previously been enabled for input, this will remove it.
320+
*
321+
* The Interactive Object that was assigned to this Game Object will be destroyed,
322+
* removed from the Input Manager and cleared from this Game Object.
323+
*
324+
* If you wish to re-enable this Game Object at a later date you will need to
325+
* re-create its InteractiveOobject by calling `setInteractive` again.
326+
*
327+
* If you wish to only temporarily stop an object from receiving input then use
328+
* `disableInteractive` instead, as that toggles the interactive state, where-as
329+
* this erases it completely.
330+
*
331+
* @method Phaser.GameObjects.GameObject#removeInteractive
332+
* @since 3.7.0
333+
*
334+
* @return {Phaser.GameObjects.GameObject} This GameObject.
335+
*/
336+
removeInteractive: function ()
337+
{
338+
this.scene.sys.input.clear(this);
339+
340+
this.input = undefined;
341+
342+
return this;
343+
},
344+
294345
/**
295346
* To be overridden by custom GameObjects. Allows base objects to be used in a Pool.
296347
*

0 commit comments

Comments
 (0)