I'm developing a multiplayer turn-based card game. In certain scenarios, the clients are required to perform an animation before moving on with the game. For example, the server informs the clients to animate dealing cards to all players. This animation takes around 5 seconds. Afterwards, the server informs a client to make a move, with a timer showing how long they have to play.

How can the server wait for the animation to finish before moving on and starting a timer and informing a client to play? The timer obviously needs to start after the animations are complete.

I've thought of the following:

1) Hardcode the animation durations on the server side and delay sending out the next message to the clients until after the duration of the animation.

2) Have the clients inform the server when an animation is complete.

..but I feel that there should be a better way.

Is there any other way to do this?


1 Answer 1


Due to network latency, hard coding the animation duration on the server won’t necessarily work well. Especially if the animation could vary based on frame rate, or if the animation is skippable. What I have done before is have a general “grace period” timer of X seconds, which is long enough to accommodate any animation that might play plus a few seconds network latency. As soon as the client reaches the end of the animation, it notifies the server, whereupon the server continues gameplay. But if the server has not received the notification in time, it will either kick the player out or give other players an option to do so (with a few more seconds delay, just in case).

You can also get more complex by having the client send regular updates about its current state (eg. how far along it is in the animation), and the server can verify that the client is progressing in a timely manner. If the server stops receiving these updates, or the client does not seem to be progressing, the server can act accordingly, without having to wait for the end of the animation to tell whether the client has stopped responding.


You must log in to answer this question.

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