I am currently working on a Warfare 1917 like game. Right now I am trying to get the combat system working. I have made animations for a running and shooting soldier. It takes exactly 0.5 seconds till the animation lets the soldier shoot.

I have taken out the animations, hud etc. because I put much effort in them and I don't want someone to steal them just now. :) It currently looks like this:

Obviously they are killing each other too fast. How can I let them wait till the animation is at the point where they can calculate if they die or not?

This is my code. First it checks if two "soldiers" are in each others vicinity and then I calculate who of those two will die. german.stop(true); britain.stop(true);In the class where I handle the spawning and the animations of my soldiers I have a simple if else statement. Whenever stop = true then the soldier will stay at his current position and does his shooting animation. That this soldier continues to run after killing the other soldier is also a problem, but that's something for a later time.

ArrayList<britain> britainToRemove = new ArrayList<britain>();

ArrayList<germans> germansToRemove = new ArrayList<germans>();

    for (int i = german_array.size() - 1; i >= 0; i--) {
        germans german = german_array.get(i);
        for (int j = britain_array.size() - 1; j >= 0; j--) {
            britain britain = britain_array.get(j);
            if (german.getBounds().overlaps(britain.getBounds())) {
                //handle collision
                int german_hit = random.nextInt(100) + 0;
                int britain_hit = random.nextInt(100) + 0;
                message = "Red: " + german_hit + "Blue: " + britain_hit;
                if (german_hit > britain_hit) {


                } else {



Assuming you are using LibGDX Animation class, you can use isAnimationFinished() method to check if animation has finished or not.

When you start your animation, you need to store starting time and subtract current time from it. Obviously, this needs to run as a separate loop with objects waiting for their animation to finish. You could use britainToRemove and germansToRemove for that. Iterate through these lists and remove elements from britain_array and german_array only when their animation finishes (don't forget to remove them from the list you are iterating through).

Note: My suggestion would make the two *toRemove lists state objects.

EDIT: If you care about performance, you should use PriorityQueue instead of iterating through the whole list.


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.