Crafty.js multiplayer platform game, keeping players in sync
- by johnwards
I'm using crafty.js to create a very simple platform game. It doesn't need to stop cheating, it's actually just seeing other players move around, and it doesn't need to have collision detection between players. They are "shadows".
How I've gone about it so far is to use http://pubnub.com to send messages between clients. These messages are simple. The first if a new player arrival, the second is a key down and the third is a key up.
The code is here: https://github.com/whiteoctober/craftyconcept
However I've hit against the old chestnut of keeping everything in sync.
At the moment I'm letting the each of the clients decide where to place the other players based on the received key events, I also only move "you" until I get a key press event back from pubsub. My thinking here is to try and keep things in sync!
However it isn't perfect, http://www.whiteoctober.co.uk/john/gametest/, things can get out of sync very easily. Key presses arrive in the wrong order etc.
Is there any simple solutions to this, I would like to keep it all client side (with pubnub) and not have a central server with positions etc if possible.