1
\$\begingroup\$

I'm making a three in line game with godot, but i'm having an issue.

First time when swapping cells, the animation of swapping and the elimination of cells (in the case of making 3 or more cell aligned in a line) played both at the same time.

So i refactored a bit the code, now i have queue for each cell that manages the animation to be played one by one.

Now my problem is this, the cells that the player swaps, they do fine, the play the swap animation then the elimination animation. the problem are the other cells in the line, those get removed as the first cells are playing the swap animation first and then elimination animation.

| *              | Step 1           | Step 2          |  
| cells in line  |  remove animation|   nothing       |
| swaped cells   |  swap animation  | remove animation|

in case i didn't explained well i left a more graphic description of the flow of the animation steps.

this is how i want the animation to be played

| *              | Step 1           | Step 2            |  
| cells in line  |  nothing         |   remove animation|
| swaped cells   |  swap animation  | remove animation  |

I'm not sure how to solve the problem, each cell manages their animations in the queue.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

If I understand correctly, you have a script that initiates swap and remove animations. I presume it does so by interacting with multiple AnimationPlayer. However, you want to play the remove animations after all the swap animations have completed.

To do that, in the script that initiates the swap animations keep track of how many. Each time you start playing a swap animation you increment the count… Use connect on the animation players animation_finished signal, and in the handler you decrement the count (you can use CONNECT_ONESHOT so it disconnects automatically). When the count reaches zero in the handler, it means all the swap animations are done, then you play the remove animations.

If you are using Tween instead of AnimationPlayer you want the tween_completed signal instead.


For re-usability, I suggest to create a new script that has the logic of playing an animation over a list of nodes, and emit (with emit_signal) a signal when they all completed. Then you can use it from your current script. You would tell it to play the swap animation on a set of nodes, yield on your signal, and then tell it to play the remove animation on the other set of nodes.

\$\endgroup\$

You must log in to answer this question.

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