我正在尝试使用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的初学者,所以我不知道如何将场景从这个服务器端代码导入到客户机视口中。有这样的客户端示例代码吗?或者如何使用套接字将场景信息从服务器发送到客户端?如何显示它们?
发布于 2015-04-28 12:11:31
你应该在服务器端和客户端以同步流的方式计算物理,并且只在客户端渲染场景数据。看看Ironbane的源代码。
https://stackoverflow.com/questions/26204153
复制相似问题