0

I'm trying to make a simple web online game using physijs and node.js

I found a related source from here (https://github.com/jjoe64/nodejs-physijs)

and below is the basic server-side code that I want to use.

'use strict';

var THREE = require('./libs/three.js');
var Ammo = require('./libs/ammo.js');
var Physijs = require('./libs/physi.js')(THREE, Ammo);



/////////////////
// game

var initScene, render, renderer, scene, camera, box_falling;

initScene = function() {

    scene = new Physijs.Scene;

    // Box
    box_falling = new Physijs.BoxMesh(
        new THREE.CubeGeometry( 5, 5, 5 ),
        new THREE.MeshBasicMaterial({ color: 0x888888 })
    );
    scene.add( box_falling );

    // Box
    var box = new Physijs.BoxMesh(
        new THREE.CubeGeometry( 5, 5, 5 ),
        new THREE.MeshBasicMaterial({ color: 0x880088 }),
        0
    );
    box.position.y = -20;
    scene.add( box );

    setTimeout( render, 200 );
};

render = function() {
    scene.simulate(); // run physics
    setTimeout( render, 200 );
};


//////////////////
// web socket

var io = require('socket.io').listen(8088);

(function() {
    io.sockets.on('connection', function (socket) {
        console.log('client conneted');
    });

    // start physijs scene
    initScene();
})();

the problem is, I am so beginner of node.js and socket.io, so I do not know how to import the scene from this server-side code to the client's viewport. is there any client-side sample code of this? or how can I emit the scene information from server to client using sockets? how can I display them?

EJ Shim
  • 11
  • 2

1 Answers1

0

You should have the physics being calculated on the server side and client side in a synchronizedream way, and only render the scene date on the client side. Take a look at the source for Ironbane.