0
網絡遊戲
我試圖用physijs做一個簡單的網絡在線遊戲和Node.js的與three.js所,physijs和Node.js的
我發現了一個相關的源從這裏(https://github.com/jjoe64/nodejs-physijs)
以下是我想要使用的基本服務器端代碼。
'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();
})();
的問題是,我這樣的Node.js和socket.io的初學者,所以我不知道如何從這個服務器端代碼到客戶端的視口導入現場。 有沒有客戶端的示例代碼?或者我如何使用套接字從服務器發送到客戶端的場景信息?我如何顯示它們?