Change opacity of entire game object?

I’ve been searching for an answer to this but have not found exactly what I’m trying to do.

I know I can change tint.w of a sprite to get it to fade out. This can even be animated.

My question however is: suppose I build a game object of many (more than one) sprite components. Is there a way for me to just change the opacity of the entire game object and perhaps all arbitrarily nested game objects which may further have sprites associated?

I’m thinking of a case where I might have a character with different body parts, weapons and clothes. How can I do this in one shot for the entire character if possible?

Thanks for any and all help!

Cheers!

-deckarep

Tricky to do as the alpha channel works at a component level as you know.

You could use a custom material for your sprites and manipulate the alpha channel of that instead.

Personally I’ve always just kept track of my sprites internally and named them 1-6 for example and use a loop to set the alpha values.

7 Likes

you can only change opacity component by component and it should be understood that below the overlying parts of the object, the underlying parts will be visible. To “properly” change the opacity of an entire object you can try to render it separately from the rest of the objects into a personal render target texture and use that for the semi-transparent output. The same for outline, blur and so on. Not easy, but this is the way.

Also remember that changing the tint requires additional draw calls in the render. It is not a good idea to change the colour and transparency of hundreds of sprites in this way. (better as benjames171 wrote above)

4 Likes

There is a way to do this, but you have to programme it yourself. Create a table with the addresses of the sprites then use this code.

self.sprites = { "head#sprite", "body#sprite" }

for k, v in pairs(self.sprites) do
    Go.set(v, "tint.w", 0)
end 

(Is that right?)

3 Likes

Thanks all for the help. The community has been great.

I figured it would boil down to just doing things individually when I need to go down this path.

I’ll also keep in mind that a custom material might be a better way in the future.

Thanks so much for clarifying!