Libgdx: getRawDeltaTime() should return 0 when setContinuousRendering() changed from false to true

Created on 28 Dec 2013  ·  3Comments  ·  Source: libgdx/libgdx

In most backends there is no way to reset detlaTime... This lead to the impossibility to switch from non continuous rendering to continuous rendering when an animation is needed (specially when animating menus in scene2d.ui). For example, when setting an animation like this :

final TextButton button = new TextButton("New Game", textButtonStyle);
button.addListener(new ClickListener() {
    public void clicked(InputEvent event, float x, float y) {
        Gdx.app.debug("TestApplication", "button clicked");
        MoveToAction outAction = Actions.action(MoveToAction.class);
        outAction.setPosition(0, 0);
        outAction.setDuration(.5f);
        outAction.setInterpolation(Interpolation.pow2Out);
        button.addAction(Actions.sequence(outAction, Actions.run(new Runnable() {
            @Override
            public void run() {
                Gdx.graphics.setContinuousRendering(false);
                Gdx.graphics.requestRendering();
            }
        })));
        Gdx.graphics.setContinuousRendering(true);
    }
});

When the button is pressed in non continous rendering, the appearence is updated but if the up event lead to the click event 1 second after the down event, the getDeltaTime() is bigger than the animation duration... so setting continuous rendering to true has no effect and the animation finished immediatelly.

I would like to have a way to set the deltaTime to zero when changing to continuous rendering so that the first _new_ frame match the first frame of the animation (and not the last one) :

  • withing the setContinousRendering() method of each backend
  • with a new setDeltaTime() and setRawDeltaTime()

I'm doing it with introspection wich is not really a good way but save me a lot of battery life and keep the animations.

What do you think ?

Most helpful comment

You could (and should) cap the delta time to a maximum value.

See how it is done in https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/ActionTest.java

All 3 comments

You could (and should) cap the delta time to a maximum value.

See how it is done in https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/ActionTest.java

That's a good workaround !

Try this
maxtime=0.2f
delta = delta > maxTime ? maxTime: delta ;
skips at max 5 frames if u get 30fps (lowest allowable for smooth movement)

Was this page helpful?
0 / 5 - 0 ratings