Make Actor Clip Child Image

I want the actor to draw stretchable, but snap it to the size of the actor. I derived this class from Widget and used some hardcoded values ​​as a simple test:

public class MyWidget extends Widget {

    public MyWidget(Drawable drawable) {
        setDrawable(drawable);
        setSize(100, 100);
    }

    public void draw(Batch batch, float parentAlpha) {
        clipBegin(getX(), getY(), 20, 20);

        drawable.draw(batch, getX(), getY(), 500, 500);

        clipEnd();
    }
}

No pruning is performed, although pushed spills out of the actor's limits. This actor is part of the table, if that matters. I believe that I am using clipBegin () / clipEnd () methods incorrectly. What is the right way to do this?

thank

+4
source share
1 answer

This is what I found based on comments and my own experiments. It is important to clear the package before starting the clip and after drawing to ensure proper drawing.

public void draw(Batch batch, float parentAlpha) {
    batch.flush();
    if (clipBegin(getX(), getY(), 20.0f, 20.0f)) {
        //do your drawing here
        drawable.draw(batch, getX(), getY(), 500, 500);
        batch.flush();
        clipEnd();
    }
}
+2
source

All Articles