Is it possible to swap palette when drawing a SpriteBatch?
When I swapping palette using this method it applies to the entire image, not individual quads 😢
Posted Jan 21, 2022, 2:13 AM UTC
711
When I swapping palette using this method it applies to the entire image, not individual quads 😢
Posted Jan 21, 2022, 2:13 AM UTC
If the footprint of your sprites is relatively small (all can fit within 512 x 512) I'd recommend splinting your approach in two.
At load time, draw your images with the colour variants you need to a canvas with known offsets using the approach you reference.
At draw time, use that canvas as the image for your batch render. When you want to shift the pallet for a single sprite, just change it's offset to match the colour variants you drew to your canvas on load time.
Thanks for the advice, that's exactly what I did.
A SpriteBatch's sprites are drawn from the same texture. Changing the texture will affect all sprites that use it.
That's bad. I was hoping that this problem could somehow be solved with
SpriteBatch:attachAttribute. It turns out that if I need to draw a lot of the same buttons, applying different palettes to them, I have to first draw all their variants in memory and then add to the overall texture. The weird thing is that I can change the color for an individual sprite usingSpriteBatch:setColor, but I can't change the palette. Anyway, thanks for the answer!So what is it exactly you're trying to accomplish? Have lots of buttons with different colours? Is there any reason you can't add the different variants to memory, or use shaders?
Also, I'm assuming setColor alters the image itself, while changing the palette alters the image data. It's the equivalent of changing the word "dog" to "dag" by substituting the o with an a, as opposed to altering the alphabet itself to make the letter "o" look like "a".
I'll show you two examples.
In the first example, I change the lighting of the overall picture by changing the palette. The number of colors in the palette does not exceed 16. The colors just change places. Here I have no problem as long as I don't need SpriteBatch.
In the second example, I have two objects: a button and a cube. I want to recolor them dynamically when adding in SpriteBatch. For example, if I have 4 factions of identical units in the game that only differ in their palettes, I wouldn't want to repaint them all manually.
In that case, I'd probably just use four batches - one for each faction.
There is no such reason, I just thought that there is a more simple/correct way.
Unfortunately, I don't know how to use shaders for this purpose (and in general). If you can teach me, I would be very grateful.
I've never used them either, but surely you can just read the docs or find something online?