Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

Your problem is that you are making the clients decide where to put the chars. And that will invitable make them out of sync, when you only send keyboard presses, that would only work with a central server, which would keep all they correct data.

If you really want to avoid a centreal server, the way you can do it is by sending the coordinates instead of keypresses, like saying [player 1, x: 20, y: 500]

That way you can make each client broadcast theirs OWN player position.

I would that would work for a start.

share|improve this answer
    
So I've sort of done this now. For local players I'm letting the game engine decide what to do with keypresses as normal. I just broadcast a move/stop with X & Y coords. I update the remote players position based on that X & Y. Sometimes players jump about a bit, but it is okay. Full live version can be found here: allyourbaseconf.com –  johnwards Sep 3 '12 at 13:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.