1
\$\begingroup\$

I've also asked this question on StackOverflow.

In a Libgdx game, I have some Animations for my Player. All the Frames for this Animation are inside a TextureAtlas. The Player Textures show a human, with a white T-Shirt. The T-Shirt is the only white part of the Player.
Now i want to be able to replace the white color with red for Player1, with green for Player2 and so on. How can I do that, without losing the advantage of the TextureAtlas (Texture switching)?

Of course 1 way would be to store 4 versions of every Frame, for 4 different Players (colors). However, there are games out there where you can fully customize the Player, give them a blue hat, red pants, and pink shirts and so on. How can this be done?

\$\endgroup\$
4
  • \$\begingroup\$ There are a bunch of answers for this on the StackOverflow original already. Could you flag it with a moderator to get it migrated? \$\endgroup\$
    – Anko
    Jun 12, 2014 at 13:21
  • \$\begingroup\$ This question has already been asked on stackoverflow.com \$\endgroup\$
    – House
    Jun 12, 2014 at 13:26
  • \$\begingroup\$ Please don't cross post. If you think the question belongs here, have it moved here, don't ask it again here. \$\endgroup\$
    – House
    Jun 12, 2014 at 13:28
  • \$\begingroup\$ @Byte56 oh sorry i did not know that thats possible... \$\endgroup\$
    – Robert P
    Jun 12, 2014 at 13:29

1 Answer 1

3
\$\begingroup\$

Just use a white texture for the t-shirt. When you draw, change the color of the batch to the color you want for t-shirt. After you draw, change the color of the batch to the original.

I assume you have separate parts for your player and not one texture for the entire player. Parts meaning head, arms, legs, neck, body..etc. That's how other games you mentioned should do it.

\$\endgroup\$
8
  • \$\begingroup\$ I planed to have one texture for the whole player, wouldn't it be hard to have a working Animation, if all parts are separated? \$\endgroup\$
    – Robert P
    Jun 12, 2014 at 13:28
  • \$\begingroup\$ No, it won't be hard at all. \$\endgroup\$
    – Saj
    Jun 13, 2014 at 8:39
  • \$\begingroup\$ Okay, thanks for the answer. So i would have 1 Texture in the TextureAtlas, which is only the T-Shirt, in a white color and the i set the color of the SpriteBatch before drawing the T-Shirt and the i reset it to the standard color right? \$\endgroup\$
    – Robert P
    Jun 13, 2014 at 8:46
  • \$\begingroup\$ Yes..that sounds correct. \$\endgroup\$
    – Saj
    Jun 13, 2014 at 13:12
  • \$\begingroup\$ Okay thanks a lot! Is there no easier way with only one Texture, if i only want to customize the T-Shirt? \$\endgroup\$
    – Robert P
    Jun 13, 2014 at 13:22

Not the answer you're looking for? Browse other questions tagged .