0
\$\begingroup\$

I want to make a screenshot with

ScreenUtils.getFrameBufferPixmap(x, y, w, h);

I call this function in Actions.run(new Runnable{...}) in scene2d.ui, and the problem is that actions are called at very beginning of a new frame, so nothing is rendered yet.

How to call this method properly, e.g.

Scene.inTheEnd(run(ScreenUtils.getFrameBufferPixmap(x, y, w, h);));

?

\$\endgroup\$
1
\$\begingroup\$

A Stage has the 2 methods act() and draw().
The act() method calls act() for all it's Actors. The Actors act() method updates all it's Actions, so your screenshot is taken while the Stage is acting.
The draw() method calls draw() for all (visible) Actors and is usually called after the act() method.
The screenshot should be taken after the draw() method. Usually act() and draw() should be called inside the render of your Screen or ApplicationListener and there you should also take the screenshot:

public void render (float delta) {
    this.stage.act(delta);
    this.stage.draw();
    Pixmap screenshot = ScreenUtils.getFrameBufferPixmap(x, y, w, h);
    // do something with the screenshot
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.