The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I create a project for android devices.
object A is in front of object B. Both play SFX when I try to touch the part between the two objects (see picture, mark red circle), I want to play SFX on object A when it touches the part between the two objects. please help me
mark red

Godot version latest
in Engine by (15 points)

I do not see the Image. Maybe add some code?

I have two Area2D with input event touch screen, both object play SFX. When I touch on the area (mark red on the picture) both objects play SFX, I want just object on front only play SFX, Object A in front of object B.
mark red

2 Answers

0 votes
Best answer

Reading the class-node-method-input docs you can stop the event to get handled by other nodes

To consume the input event and stop it propagating further to other nodes, SceneTree.setinputas_handled() can be called.

So you can add this code SceneTree.set_input_as_handled() to your touch event handler for both A and B.

by (646 points)
selected by

this method work when I change the node type from Area2D to Node2D and change the sprite to touchbutton then delete collision2D

0 votes

There are several possible ways to implement something like this

  • Have some code on Object A which stops the sound which Object B played
  • Have some code on Object B which checks if you're touching Object A, before playing a sound
  • Have some kind of "Sound Manager" node which knows about Object A and Object B, and has conditional logic to play one of the two sounds
by (176 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.