Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Robster | |
Old Version | Published before Godot 3 was released. |
Hi all,
I am still struggling with this. I know it will “click” at some point so I’m hoping this is that moment.
I am building a breakout / arkanoid clone.
I have many brick nodes on screen.
When the ball hits the bricks, they explode.
I want to know what texture the brick contains, so the particles can use that to their advantage.
So in my brick.gd scene I have:
var currentTexture = get_node("TextureButton").get_normal_texture()
var currentTextureName = currentTexture.get_path()
emit_signal("brickColour", currentTextureName)
In my particle scene I have:
func _ready():
connect("brickColour", self, "setParticleTexture")
func setParticleTexture(colour):
print ("texture is : ", colour)
The problem is that Print statement never occurs. Nothing is being sent (or received at least).
Now I KNOW that in my particle scene I need to have something like:
func _ready():
var brick = get_node("/path/to/brick")
brick.connect("brickColour", self, "setParticleTexture")
BUT I don’t know what that path is to each brick as there are HEAPS of bricks and they are named in various strange names that have been assigned to them. So I can’t know what bricks name it was, that sent the signal.
How can I get around this? There MUST be a way, I just can’t wrap my head around it.
Any help would be very much appreciated.
Are the particles spawned from the bricks? You don’t need signals for that, just set the texture directly to the instance of the particle, like:
var particle = particle_class.new()
particle.set_texture(load(texture_path))
# add the particle to the scene
If the particle is a Sprite node, that is. Otherwise you would create a variable called texture_path
in the particle and set the sprite texture to that value on ready:
var texture_path = ""
func _ready():
get_node("sprite").set_texture(load(texture_path))
And in the spawn code:
# ...
particle.texture_path = texture_path
# add particle to the scene
manokara | 2017-07-26 05:03
Hey there, thanks for replying.
The particles are in another scene that is instanced when required (when a ball hits a brick). I want to keep it that way as they have other things they do and I like it being separate.
If I can figure out how to get the signals to work then I can keep that separation of scenes.
Robster | 2017-07-26 05:59
Presumably, at some point you know the position where the collision occured and pass that along to whatever code spawns the particle scene. In order to set the position of the particles.
Assuming that, wouldn’t you also be able to get the brick involved in the collision, determine its color and pass that information to the particle scene, along with the position?
You wouldn’t need to use signals at all in that case.
If you really do need to use signals, maybe it would be better to connect to a central node that emits the needed signals…
One that can be easily reached from all nodes that need to communicate… say the level itself, or a singleton.
Then at the point where the brick emits the signal, have that central node emit the signal instead.
aozasori | 2017-07-26 13:42