Jump to content

Enabling and disabling inputs


will-e
 Share

Recommended Posts

Hi!

 

I started to work with Phaser couple days ago and I am pretty new to Javascript as well, so the answer to my question might be simple. My game has a button that is supposed to enable inputs on some sprites and pressing this button again should disable those. Inputs are first disabled as they should, pressing a button will make them enabled nicely, pressing the button again will disable them as it should, but then second time trying to enable the inputs it will stay disabled.

 

Any help is appreciated, thanks!

	function doScanner() { //function that is launched when scanner button is pressed		if (this.scannerOn==false) {			this.scannerOn=true;			for (var i = 0; i < this.scannableAssets.length; i++) { //loop all trough all assets that are  scannable and enable inputs				this.scannableAssets[i].inputEnabled = true; //enable this far disabled input for them				this.scannableAssets[i].events.onInputDown.add(function() { this.scannerText('this should be above hero'); }, this);			}						}		else { //here we reverse everything			this.scannerOn=false;						    for (var i = 0; i < this.scannableAssets.length; i++) {					this.scannableAssets[i].inputEnabled = false; //disable the input				}						}	}
Link to comment
Share on other sites

Can I ask why you're disabling the inputs? Is there a specific reason in your game to do this? (I assume so, but I'm just checking).

 

If you just want to temporarily turn off the input for an object, but you will need to use it again in the future, then I would do it like this:

sprite.input.enabled = false;sprite.input.enabled = true;

As this is a 'soft toggle' and won't force a complete input handler reset.

Link to comment
Share on other sites

Awesome, thanks! That worked.

 

In this game there is a alien with a special scanner, that can retrieve information about the surroundings, but the scanner needs to be turned on first with a button.

Link to comment
Share on other sites

  • 1 year later...

Can I ask why you're disabling the inputs? Is there a specific reason in your game to do this? (I assume so, but I'm just checking).

 

If you just want to temporarily turn off the input for an object, but you will need to use it again in the future, then I would do it like this:

sprite.input.enabled = false;sprite.input.enabled = true;

As this is a 'soft toggle' and won't force a complete input handler reset.

 

Hi rich,

 

You said this way is "soft toggle", then is there a way to do a "hard toggle"? How? I'm having problems with the "useHandCursor" behaviour and I think this can be maybe related with the way I'm changing the "inputEnabled" property.

 

Thanks a lot!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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