Is there a quick way to change sprite transparency? (SOLVED)

I’d like to be able to change the alpha channel for a sprite so that the whole sprite can appear transparent when certain things happen, I’d prefer not to create a bunch of new PNGs with the alpha baked in as I’d like to be able to animate the level and don’t want to incur the cost of having dozens of images. I’ve hunted around and can’t find an obvious way of controlling this, what’s the simplest way of achieving this?

Thanks in advance.

1 Like

There’s an Alpha setting for each sprite that can do exactly this. Just set it to 0.5 or whatever number suits you.

I have to say: it took me a REALLY long time to find this the other day.

the code is

sprite.set_constant("#sprite", "tint", vmath.vector4(1, 1, 1, 1))

and those four values are R, G, B, and Alpha. (1, 1, 1, 1) is normal, and 1, 1, 1, 0 is completely transparent.

4 Likes

Excellent, this is exactly what i was looking for.

I agree. If you search for tint you get quite a few hints, but it should perhaps be explicitly documented? Is there some way we can improve the documentation around this recurring question @sicher?

Anyone that uses this code for their own projects, please not that the quotes for the first two parameters of the line of code that 88.josh left are different, and you’ll have to change the second set of quotes for the code to compile correctly.

Thanks for the code 88.josh! Helped me out a lot :slight_smile:

I edited his post to fix the quotes. Thanks for pointing it out!

1 Like