1

I'm currently making a test game with LibGDX for Java. In the test, I randomly generate a sort of "height map", resulting in a 2-dimensional set of lines stored in a ChainShape. Basically, everything below the lines will be ground, and everything above. Here's a graphical representation, with the black line being my ChainShape:

Height Map

I plan on having a single texture for the ground (in this example, it would be solid yellow), which is as tall and wide as the world's bounds.

My problem is this: I need to crop out the ground image so that the ground does not pass the black line and overlap the sky. I was planning on using a TextureRegion, but that can only crop rectangular portions.

Does anyone know of a LibGDX method or workaround that would allow me to use the bounds of a Shape to determine where to crop an image?

Thanks in advance.

user2029675
  • 245
  • 3
  • 9
  • This seems related: http://stackoverflow.com/questions/13766978/drawing-textured-polygons-with-libgdx – P.T. Jun 29 '13 at 06:19
  • And this one: http://stackoverflow.com/questions/10547897/how-to-draw-custom-shapes-using-a-simple-texture-in-libgdx – P.T. Jun 29 '13 at 06:20

1 Answers1

1

One Solution for your problem can be that you can create a Mesh with the vertices stored in ChainShape and render your Mesh with that texture.

This method won't crop your image but can be a solution to your problem by rendering the texture so that it wont go above black line in your bounds..

Vikalp Jain
  • 1,419
  • 1
  • 11
  • 20