Setting alpha of a game object's children

My game has a number of background game objects containing an arbitrary number of sprites and tilemaps (to save bandwidth I’m re-using sprites and laying them out by hand inside Defold).

After a quick search I learned that game objects don’t have an alpha property, so I would have to set alpha on each sprite+tilemap individually. Is there a way of getting the “children” object of a game object? Or is there another way of achieving the same result?

You should use your own list of children objects.
Also, notice that sprites with alfa/tint break batching: Draw calls and Defold

2 Likes

My mind is used to nested sprites, I need to get used to the Defold Way ™. :)Thanks!

On this note, I’m trying to dynamically get all the sprites inside a game object. This is my approach:

  1. Use .fragment to guess the name of the sprite (do until, “sprite1”, “sprite2” etc)
  2. Check is the sprite exists by using pcall to check its scale

This feels like a hack. Is there a better way of finding out if a sprite exists? Or indeed to find all sprites inside a game object some other way?

I like to think Defolds is telling you: “Everything that exists in runtime you put there, so you know about it”

Meaning that if you put a sprite in a collection or spawned it by a factory you know that and can track it. So you would track all your sprite1, sprite2 etc and then from there tint them.

1 Like

I kind of agree, but there is one caveat with this thinking: Separating art from code. The code, in my opinion, shouldn’t limit the artist (or create an inflexible workflow). Is there really no way around this?

1 Like

Can’t you set a custom material that you either hardcode the tint for or set in the renderscript?

Would that allow me to animate the fade out? Sorry, still new to Defold but learning fast!

You can have a go.property() that you animate and msg.post() to your renderscript.

1 Like