Question

I want switch between Run and Jump animations, but i have some problems : If the Player run and i tap on the screen, the Player start Jumping (one time), and the Jumpanimation starts but don´t end , so the player is running with the Jumpanimation.

Do you know where my fault is? My code :

// Runanimation + Player Run
public void setRunning()
        {
                canRun = true;

                final long[] PLAYER_ANIMATE = new long[] { 100, 100, 100,};

                animate(PLAYER_ANIMATE, 0, 2, true);
        }
// Jumpanimation + Player Jump 
        public void jump()
        {
                if (footContacts < 1)
                {
                        return;
                }
                body.setLinearVelocity(new Vector2(body.getLinearVelocity().x, 10));

                final long[] PLAYER_JUMP_ANIMATE = new long[] { 100, 100, 100, 100, 100, 100};

                animate(PLAYER_JUMP_ANIMATE, 0, 5,true);

        }

Thx Seref

Was it helpful?

Solution

You are animating with loop boolean set to true, which means its keep looping animation. You should have some kinds of flags (booleans) like jumping and running, so inside set running method you should check if jumping equals true, and if so, stopAnimation() and animate using different frames (in this case running)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top