0
\$\begingroup\$

I have been following the tutorial https://www.youtube.com/watch?v=1fJrhgc0RRw&list=PLZm85UZQLd2SXQzsF-a0-pPF6IWDDdrXt&index=11

I an not able to understand what is stateTimer in getframe method and how is that initialized?

\$\endgroup\$
0
\$\begingroup\$

It would be easier if you give us link with video timestamp:

https://youtu.be/1fJrhgc0RRw?list=PLZm85UZQLd2SXQzsF-a0-pPF6IWDDdrXt&t=620

"stateTimer" is float variable that, you need to reset (=0) it every time you start new type of animation (new state). When variable stateTimer is 0, current animation will start with first frame. Timer is increased by delta time and after defined duration between two frames method getKeyFrame will return next frame etc...

In short stateTimer is current animation timer. Org. code (this is called ones per render call):

    //if the current state is the same as the previous state increase the state timer.
    //otherwise the state has changed and we need to reset timer.
    stateTimer = currentState == previousState ? stateTimer + dt : 0;

Code is from example: https://github.com/BrentAureli/SuperMario/blob/dc48dcb6d5b25e8b3c22908df23a5328f13868f9/core/src/com/brentaureli/mariobros/Sprites/Mario.java

\$\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.