0
\$\begingroup\$

I am creating a 2D game with LibGdx that will have creatures that are generated from dozens of characteristics with potentially millions of unique combinations. For each segment of each creature, I want to use two sprites so that I can mix shapes and colors and cut down on my resources. I would like one sprite to be a black and white (or grayscale) of the shape of the body part while the second sprite is just a color pattern. I think I may need to write a shader that splices the color pattern onto my shape to give me the sprite I need. I just need some guidance on how to get started.

Another way of explaining this is with the example of clothing. I want to be able to draw a shirt shape, and pants shape, a socks shape, etc. and also draw different fabric patterns. Then I would mix and match the clothing with the pattern instead of drawing every possible combination. How can I accomplish this with LibGdx?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

It sounds like what you are trying to achieve is masking. You want to maintain the shape of a given sprite A (thus only specifying black/white info), while having a second sprite B to form the texture.

In this case, you can achieve what you want by using a depth buffer. The code example of achieving something like what you want is located in that same link.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for the good links! A buffer may be how I end up doing it, but I think I may just write my own shaders to do it. Your links led me to this good one: github.com/mattdesl/lwjgl-basics/wiki/Shaders. I'm going to leave the question open for a little while to see what else somebody might say. \$\endgroup\$
    – Amplify91
    Commented May 21, 2014 at 19:40

You must log in to answer this question.

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