I am working on a strategy game and I have 300-400 images per unit. Units will have different colors of flags according to their owner player. But my images are based on blue color so I want to swap that blue colors with other colors like red, pink, gray, etc. Have you got any idea about how to do it?
Asked
Active
Viewed 329 times
0
-
How many possible unique colors are there? If just a few, I would make different sprites for each color. If a lot, I would make the flag sprites separate from the character sprites and layer them on top of each other, and then you could color the flag sprites at run time. Or alternatively, you could create one set of sprites and run a palette swap on them like this: http://stackoverflow.com/questions/26132160/simulating-palette-swaps-with-opengl-shaders-in-libgdx/26141687#26141687 – Tenfour04 Jul 24 '15 at 13:21
-
@Tenfour04 there are 8 unique colors and 10 shades for each and there are 230 texture for each unit and there are a lot of units so I am not able to make different sprites for each color. Also there I can't seperate flag sprites because it makes lots of sprites too. I have looked into your answer before asking that question but I couldn't understand how it works. Can you explain it? – Arda Kara Jul 24 '15 at 13:33
-
Which part don't you understand? – Tenfour04 Jul 24 '15 at 15:16
-
@Tenfour04 if you want me to tell the truth I didn't understand anything :/ I tried to read the code but it is not well commented and I don't have enough knowledge about shaders. I can try to do something similar if you can explain me working logic of your code. – Arda Kara Jul 24 '15 at 15:50
-
I can't really spare the time to go through and explain every point there in detail. Can you share your current code for drawing your sprites? Then I'll know what you do understand and can add an answer where I explain what you need to change to do the palette colors. – Tenfour04 Jul 24 '15 at 15:58
-
@Tenfour04 Okay then I will try to edit your code to fit in my needs then I will share my code. – Arda Kara Jul 24 '15 at 15:59
-
1And read up some on how shaders in OpenGL ES work...there are a ton of sites that explain it in detail. You can try this one. It goes into 3D lighting which you don't need to worry about. But just get a basic idea of the function of a vertex shader and a fragment shader. – Tenfour04 Jul 24 '15 at 16:01
-
@Tenfour04 I think you forgot to add the link :) but thanks for help – Arda Kara Jul 24 '15 at 16:03
-
@Tenfour04 I made a better understanding but I have a few questions. Firstly why our reference sprite is red scaled? And how it decides which color it should use from palette? – Arda Kara Jul 24 '15 at 16:19
-
http://www.learnopengles.com/tag/vertex-shader/ – Tenfour04 Jul 24 '15 at 16:20
-
@Tenfour04 thank you – Arda Kara Jul 24 '15 at 18:50
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/84249/discussion-between-senhor-and-tenfour04). – Arda Kara Jul 25 '15 at 08:20
1 Answers
0
The SpriteBatch class has a setColor() method. When you're ready to render the Sprite you want to put a dynamic color on, do this:
batch.setColor(new Color(Color.RED));
sprite.draw(batch);
batch.setColor(old_batch_color);
You want to reset to the old batch color so your new SpriteBatch Color doesn't hit everything drawn after this particular sprite. You can also avoid this by always setting the correct SpriteBatch Color before you call sprite.draw(batch) for any particular Sprite, but the way I suggested is safer if you forget to do that.

Lee Presswood
- 210
- 2
- 15
-
Thanks for the tip but I don't want to change color of all sprite, I only want to change color of an area. – Arda Kara Jul 24 '15 at 18:50