Jump to content

Enabling and disabling inputs


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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...