Jump to content

Disable input


VitaZheltyakov
 Share

Recommended Posts

If you add them all to a group, you can do...

for(var i = 0; i <= myGroup.children.length-1; i++) {
    myGroup.children[i].input.enabled = false;
}

A better solution, may be to add a toggle variable to each input you wish to be toggled. Like this...

this.button1 = this.add.image(0, 0, 'myButton');
this.button1.toggleInput = true;

for(var i = 0; i <= this.children.length-1; i++) {
    if(this.children[i].toggleInput = true) {
        this.children[i].input.enabled = false;
    }
}

The above way will scan through the states children, and checking for a toggleInput object, if it's true, then you can change it's value. You may want to set a toggle one liner as shown here: so you don''t have to do loads of if, else's: http://stackoverflow.com/questions/11604409/toggle-a-boolean-in-javascript

Hope this helps!

Link to comment
Share on other sites

  • 8 months later...

My solution:

 

    groupsInputEnableDisable : function (groups, state) {
		for (var i in groups) {
			groups[i].forEach(function (item) {
				item.inputEnabled = state;
			});
		}
	};

And when I need to turn on/off some of the groups:

this.groupsInputEnableDisable ([group1, group2], false);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...