user2029675
user2029675

Reputation: 255

How to crop a non-rectangular section out of an image in LibGDX?

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.

Upvotes: 1

Views: 559

Answers (1)

Vikalp Jain
Vikalp Jain

Reputation: 1419

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..

Upvotes: 1

Related Questions