0 votes

In a catch game , i want to catch a moving sprite with mouse click.

I have an action "click" that i use for handling mouse input and execute a check function.

func _input(event): if event.is_action_pressed("click"): checkCatch()

I also added a code for starting the game whith a start button

func _on_BtStart_pressed():
    $BtStart.hide()
    emit_signal("start_game")

But when I click on button Start , my checkCatch() function is executed.

How can I prevent this this from happening?

in Engine by (15 points)

2 Answers

0 votes
Best answer

Hi,
you can put checkCatch() function inside _unhandled_input(event): instead of in _input(event). That way only will arrive to the game the inputs that are not handled by gui.

by (3,505 points)
selected by

Thank you for your answers.

unhandledinput(event) works fine for my issue.

I could also use a boolean variable 'gameStarted ' with my action_pressed event that would prevent checkCatch() to be executed as long as the game is not started.

func _input(event): 
   if event.is_action_pressed("click")  and gameStarted: 
       checkCatch()

Yes, you could also do that! I think that is better idea to use _unhandled_input always that you mix gui and gameplay and ui in the same scenes, as this would let you have as many controls you want without any change to code. Maybe now there is only one button and adding just one variable is not an issue, but perhaps later one you want to add other controls that sould also work when game already started without triggering gameplay effects. I dont know if im exolaining myself.

ok this sounds more efficient. I'll stick to _unhandled_input.
Thanks again.

You are welcome! If the answer solved your issue, then you may select it so others can see it's solved

0 votes

Is the button a Control? I'm new to Godot, but would the unhandled event help?

 _unhandled_input(event)
by (384 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.