简体   繁体   English

使用THREE.js,physijs和Node.js的在线游戏

[英]Online game with THREE.js, physijs and Node.js

I'm trying to make a simple web online game using physijs and node.js 我正在尝试使用physijs和node.js制作一个简单的在线网络游戏

I found a related source from here ( https://github.com/jjoe64/nodejs-physijs ) 我从这里找到了相关的资料( 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. 问题是,我是node.js和socket.io的初学者,所以我不知道如何将场景从此服务器端代码导入到客户端的视口中。 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? 如何显示它们?

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. 看看Ironbane的来源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM