1
\$\begingroup\$

I am trying to create an application using libgdx where i need an animation to be played on pressing an image button, i've been able to achieve it using this code

   if(slapBossFlag==true) {
        currentFrame = animation.getKeyFrame(timePassed, true);
            batch.begin();
            timePassed += Gdx.graphics.getDeltaTime();
        Gdx.app.log("time","time is"+timePassed);
            batch.draw(currentFrame, screenWidth / 2 - ((currentFrame.getRegionWidth()) / 2), screenHeight / 2 - ((currentFrame.getRegionHeight()) / 2));
            batch.end();
            slapBossFlag = false;
    }

the problem is the animation goes by too quickly.

i've tried setting timePassed to zero when slapBossFlag is false, and that didnt work.

Can anyone help?

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

You missuse the animation class.

you need to do the following:

currentframe = animation.getKeyFrame(Gdx.graphics.getDeltaTime(), true);

Currently you use an increasing time for your time passed. which is wrong, the animation class handles the passed time by itself.

Easier explained: Imagine a cake. If you eat constantly 3 percent you'll see it fade slowly away(what you want). On the other hand If you eat first 3 percent, than 6 percent and than 9 percent(what you have) the animation is fked up.

\$\endgroup\$
  • \$\begingroup\$ I understand what you are saying but it doesn't work. should i post entire code? \$\endgroup\$ – Storm Jun 30 '16 at 12:14

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.