SOLVED Can I change the colour of a sprite, and save it as a new sprite?

Hello,

Very simple question: Can I create a duplicate of a sprite via code, and give it a different colour? - and how?
This is to allow for compatability with some shaders that don't take into account the image_blend = skin_col line inside draw events.
I'm using GMS 2.3.


Many Thanks.
StaticSkizzles
 

jo-thijs

Member
Hello,

Very simple question: Can I create a duplicate of a sprite via code, and give it a different colour? - and how?
This is to allow for compatability with some shaders that don't take into account the image_blend = skin_col line inside draw events.
I'm using GMS 2.3.


Many Thanks.
StaticSkizzles
You can through sprite_create_from_surface.
You'd create a new surface, draw your sprite on it, edit it and then create a sprite from it.
Whether it's recommendable to do so depends on your use case.

I hope this helps!
If you have any questions, feel free to ask them!
 

jo-thijs

Member
Thank you I assume it won't work with animated sprites right? Probably still handy for a ingame photograph function :}
There is a sprite_add_from_surface function with which you can apply this to animations too.
I'm not sure how good the performance is though and how texture pages are managed with this.
 

kburkhart84

Firehammer Games
The best way is honestly to have the shader simply take into account the coloration you want as part of the shader code.

Barring that, you can either pre-create sprites' colorizing by actually creating them as separate sprites, which will take up some texture space, but be the fastest performance run-time generally, with the downside of having to do the work ahead of time and it being limited to the colors you pre-made. The shader method is going to be the best way overall most likely, but that takes coding the shader.

Doing it with surfaces can also work, but you need to get familiar with surfaces. Note that sprites created from surfaces(similar to sprites loaded during run-time instead of in the IDE, and sprites that are marked "use for 3d") will get their own separate texture pages. On desktop, this isn't generally that big of a deal, though it can be worse for other exports, like HTML5 and mobile. Remember that many modern 3d engines don't do texture atlas stuff at all and the work just fine, so having a few extra texture pages is not generally going to be an issue just depending on how many you have and where the game is being played.
 
Top