6
\$\begingroup\$

In my game the character movement animations work fine but now I'm trying to do a sequence of programmatic animations, for an enemy character, and it's proving to be a pain.

I'm just doing it on Android.

I have the enemy character doing a walking animation till it reaches and end position, then I want it to do a three frame throw animation. It's walk animation is fine.

Since I only want to do the throw animation frames once, I tried to use Animation.PlayMode.NORMAL, and try to use isAnimationFinished().

I also tried to get the frame number using getKeyFrameIndex() to try to detect when it showed the last frame.

But in both cases, when it reaches the end position, either I just see a flash of one of the throwing frames, or nothing at all, and it says it's "finished" with the animation, using one of the above ways to test it.

objectBatch.draw(
    animation.getKeyFrame(throwingSkeletonObject.fStateTime),
    throwingSkeletonObject.position.x,  // x
    throwingSkeletonObject.position.y,  // y
    1,      // width
    1);     // height

I'm using the fStateTime that was passed into the Object from the update() of the Object. For the walking animation I use:

 animation.setPlayMode(Animation.PlayMode.LOOP);

and for the throw animation:

 animation.setPlayMode(Animation.PlayMode.NORMAL);

The frameDuration for the walk animation is 0.7f and for the throw 0.3f.

So what do I need to do to be able to actually see all the frames of the throw animation, and then be able to tell when that's "finished", so I can go back to the walk animation going the other way or whatever?

I've tried lots of different combinations of things, including using a slower throw frameDuration, and nothing seems to really work.

Eventually I want to try to get the Boss animations going and those are much more complicated, so I want to get this fairly simple sequence to work.

UPDATE:

In the update() I'm doing:

throwingSkeletonObject.fStateTime += fDeltaTime;

The game is 2D, and I'm not using scene2D.

UPDATE SOLVED?:

I wrote a smaller test app in hopes of replicating the problem but it worked pretty well. When it did the throw animation I reset the StateTime back to zero, so as a test, I commented that out so it used the same StateTime as the walking animation and it only showed one frame of the throwing animation, so I think that was the problem. But I'm not sure about the throwing animation "end" test, I'm hoping that that will also work now.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

The problem with the throwing animation is quite simple: timing.

You set the frameDuration to 0.3f. This is (obviously) equal to 3/10f. When you set the frameDuration, it's in terms of seconds per frame. In this case, each frame lasts 0.3 seconds for a total of under a second.

Try setting the frameDuration to 2/3f. That will result in the throw animation lasting almost exactly 2 seconds.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .