Server Side Game Logic (nodejs, socketio cocos2d-html5)

Server Side Game Logic (nodejs, socketio cocos2d-html5)
0.0 0


I’m working on a new html5 multiplayer game. In the past I’ve gone about this with almost entirely custom written code.

My approach with my previous projects is to usually get something of a working client complete with a working game logic loop, and to basically completely reuse the game logic on the server side dump the client specific stuff, add my server specific funtionality and blammo: multiplayer game with an authoritative server. This was all done with custom code, socketio, and nodejs

Now with the Cocos2D-HTML5 I’ve got all sorts of nice toys built into the system. Like tile maps, physics engines and so on. I’m relying on some of those features in my logic loop, I need to either recreate them on the server side or make use of the existing libraries or someone’s already made a server side implementation.

How do people go about this with cocos2d in general? Or more helpful, with Cocos2d-html5 in particular? How likely is it that I will be able to simply take my logic loop (which doesn’t do anything with input or output, but acts entirely on processing), import the specific cocos libraries I’m using and run it in nodejs?


My guess (and it’s only a guess since I haven’t done it myself yet) is that it should be no harder than working with any other JS framework, if you already have experience with node.js.

Speaking of which (and ignore me if you consider this highjacking your thread): have you tried the pomelo framework built on top of node.js?:


I’m facing similar problem and so far I would rather avoid loading Cocos on the server because it goes with many additional features specifically for client side like rendering etc. There is too much work to do to make it work on the server. I will probably make some “middle” object that handles operation for both client and server and load it on both sides for example:

On the client I have class “Player” that inherits from cc.Sprite. It has property called “data” that stores instance of class “PlayerInterface” (or something like that) which has such functions like “update()” to do some math to move player and properties like “position”, “speed”, “velocity” etc. So I put everything that is needed to move player in the class PlayerInterface. Now in the “update()” function of the “Player -> cc.Sprite” class I call “update()” function of the “PlayerInterface” instance. And on the server I do all the physics simulation only using PlayerInterface instance.

What do you think about such solution? Any suggestion? Is it good or wrong approach?


Hi, Paul and Lukasz

Maybe it’s a wild idea, but you may can try with node webkit:
Which should be able to work on your server, as it’s based on node js, you can use all node js APIs. So theoritically, you can use it to run cocos2d-html5 on your server.

But I never tried myself, but I’m strongly interested in the result. If you want to try, please keep me notified. My email is