Libgdx Cut image

I've been trying to "cut" an image for a while, I'll explain why and what I've tried. So I wanted to create an hp "bar" except that it is not a bar but a heart, and so although it was easy for me all I had to do was take two photos, draw them on top of each other, and then just cut one to make it appear like in hp get lost, but I couldn't find a way to cut the image.

  • The height adjustment just resizes the image, as you might have guessed
  • I've tried using textureRegion for my hack, but it's not that good.
  • I found a method called clip start that also uses scissors, but just doesn't work for some reason.

I may be using a clip, but I can't find any real documentation on it, all I do is:



I almost forgot, I am using the scene2d image, maybe the best way to get around it, but not sure if that would be.

Any ideas on how to do this would be appreciated, thanks.


source to share

1 answer

You want to use the OpenGL Scissor support provided by Libgdx. See Libgdx Clipping wiki and Libgdx documentationScissorStack


The API is not particularly friendly (it is designed to support dynamic pushing of multiple bounding boxes, which as far as I have seen are not used very often).

An important point to keep in mind about the scissors stack is that it only applies to the actual drawing commands that are issued. Since most APIs try to execute drawing commands, this means that the actual drawing may not happen when it looks like it should. To ensure clipping, you must clear any buffered draws before pressing the scissors (otherwise the wrong thing might be clipped) and before pulling out the scissors, you must clear any draw calls (otherwise the items you want to clip could have avoided the scissors).

See libgdx ScissorStack not working as expected or libGDX - as a clip or How to draw only part of the screen using SpriteBatch in libgdx? or Hide the Actors group outside their boundaries .



All Articles