2
\$\begingroup\$

I am looking for a way to run my animation a complete cycle when a button is pressed. The animation runs as long as the button is pressed but the animation takes a second to play so it becomes too short. I would like to have it played through once, even if the button only was pressed very fast.

It's a character's slash with the knife and it needs to be one complete cycle, I just don't get how to do this.

Anyone has an idea on how I could do this in a better way?

The specific code is now inside render():

 if(Gdx.input.isKeyPressed(Input.Keys.SPACE)) {
        if(direction == HEADING.NORTH) {
            animation = knifeslashnorth;
        } else if (direction == HEADING.WEST) {
            animation = knifeslashwest;
        } else if(direction == HEADING.EAST) {
            animation = knifeslasheast;
        } else if(direction == HEADING.SOUTH) {
            animation = knifeslashsouth;
        }
    }
\$\endgroup\$
5
  • \$\begingroup\$ You may want to post your entire main-application code, we can only guess right now what you already have. Here's the LibGDX wiki entry: github.com/libgdx/libgdx/wiki/2D-Animation \$\endgroup\$
    – VaTTeRGeR
    Commented Apr 28, 2015 at 20:07
  • \$\begingroup\$ Are you using Scene2D with Actors? \$\endgroup\$ Commented Apr 28, 2015 at 21:18
  • \$\begingroup\$ @StrongJoshua Yes, orthogonal camera and im drawing the batch as usual. Maybe i just need to redo it in another way. \$\endgroup\$ Commented Apr 29, 2015 at 7:18
  • \$\begingroup\$ How are you rendering the animations? You should post at least that part of the Actor. \$\endgroup\$ Commented Apr 29, 2015 at 20:26
  • \$\begingroup\$ what is happening (or what are you expecting to happen) when the user play too fast two different directions? Are you expecting to animate both animations? Just one? cancel one then animate the other? \$\endgroup\$ Commented Jul 16, 2015 at 15:50

1 Answer 1

3
\$\begingroup\$

I think it will work if you combine your input listener with:

animation.isAnimationFinished(stateTime);

While playing animation ignore attack input and let it just continue playing. When the animation finishes you can respond again and start a new animation by reseting the stateTime.

But I would also have in mind that the player can move meanwhile and there you have 2 options:

  • Allow movement and cancel animation when direction changes.
  • Also ignore directional changing input until animation finishes.

I hope it helps!

\$\endgroup\$

You must log in to answer this question.

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