I am currently in the planning stages for a 2D game for mobile devices which I will be making in C++ using cocos2d-x. The game will be turn based and each turn will have a phase in which the physics simulations will take place. It will also be cross-platform.

I am new to multiplayer networking and am wondering what the best way to synch the physics would be since Box2d does not behave exactly the same on different devices.

The simulation does not have to occur simultaneously on each device but I do need the results to be exactly the same. Ideally the players will be able to witness, on their own device, the same physics simulation( i.e. motion, bouncing, collisions ) and result that occurred during their opponents turn whenever they decide to start their own turn.

What would be the best way to do this? From my research I've come up with a couple of solutions. Should I write some server code on which I would take user input and handle all of the physics simulation, then send the results to each device? or is there a way I could handle the simulation on one device and send all of the information to the other?

Also how exactly does one send everything that happens during a simulation through the network since I can not run the simulation on each device and be guaranteed the same results? Would I just update the server( or device ) with information of what occurs during every few TimeSteps?

  • \$\begingroup\$ Also I would consider setting up my own collision detection/physics if that is a better method \$\endgroup\$
    – ash
    Feb 28, 2012 at 4:02

1 Answer 1


If you want to simulate everything on a server then you better have lots of resources, but you can use a peer model with mobile devices if you have a way to exchange connection information.

I created a multiplayer flash game using Box2D and Cirrus. It was a turn based game as well. Cirrus is a peer-peer model but I wrote some server code for bookkeeping - determining who playing in which 'room', scoreboards etc. The peers would decide who plays which turn by randomly 'drawing straws' and comparing. The client who's turn was the current turn would broadcast its 'move' to the other clients. Simulation would then happen in each client seperately.

The main problem I faced was client disconnections and inaccuracies in simulation in each of the clients. Once in five times there would be slight variations in simulation and the position of one player would be different in the different clients. I tried to solve it by making the clients broadcast their own positions to its peers after each turn was done simulating, but it did not look great since in some clients the position was so dramatically different that it looked jerky. Worse case was when one player was 'dead' in some clients but not on some others.

Simulating in a client whose turn is now and then broadcasting to others the results of simulation might work, if there are no strict time constraints. You should always consider disconnections at every stage.

  • \$\begingroup\$ Because it is a turn-based game, buffering may be used to reduce network issues and smooth the playback of the physics simulation in other devices. \$\endgroup\$
    – SkimFlux
    Feb 28, 2012 at 12:24

You must log in to answer this question.

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