It looks like you're new here. If you want to get involved, click one of these buttons!
Hi guys, I’m learning to code with Codea by doing simple projects. Now I’m doing super easy DVD screen saver, if you remember...
I’m trying to change a color of the sprite. The source is PNG file with alpha, but could not find anything in Codea documentation about colors of the image. Thanks for help!
Comments
@romanmastalir As far as I know, there’s not an easy way to change the individual colors of a sprite. There’s the tint command, but that changes the tint of the whole sprite. I’ll look around an see if I can find something.
If it’s this you are after:
Then it should be straightforward using the tint command as @dave1707 says - assuming your input sprite image is black and white.
Here you go:
I just threw this together. It’s probably not what you want but it looked interesting. Maybe someone can use it for something.
Thank you guys! It works now. The image has to be white to tint it, but works well. One additional small question. How to change size of the sprite? The original image is too big, scale function just scaled everything. Is that possible?
@romanmastalir In the sprite command, after the x,y values, you can put a value that scales the sprite itself. Try different values to get the size you want.
PS. If you put the width and height of the sprite, then it’s the original size. If you double the sizes, then the sprite is twice the width and height.
To properly change colours of a sprite you should use a shader. Going through pixels one by one is incredibly slow compared to how shaders work - they essentially do all pixels in one go.
I could throw together a simple colour-changing shader if that would be of interest to anyone as an example.
yes please
Okay, here is one. The shader is part of the file, so it's a single program. Scroll to the end for the shader stuff.