如何在A-Frame中做多用户?

时间:2017-05-12 18:29:08

标签: aframe

我可以将多用户合并到A-Frame中有哪些选项?

以下是我希望黑色球体代表每个玩家的示例代码:



<script src="https://aframe.io/releases/0.5.0/aframe.min.js"></script>

<a-scene>
  <a-sphere id="player" color="black"></a-sphere>

  <a-box position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9"></a-box>
  <a-sphere position="0 1.25 -5" radius="1.25" color="#EF2D5E"></a-sphere>
  <a-cylinder position="1 0.75 -3" radius="0.5" height="1.5" color="#FFC65D"></a-cylinder>
  <a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
  <a-sky color="#ECECEC"></a-sky>
</a-scene>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:3)

随着社区和团队继续尝试,多用户仍在充实。网络物理需要很好地实现,并且游戏行业中有一些方法可以移植到Web上。在撰写本文时,有一些初步选项:

https://github.com/haydenjameslee/networked-aframe - Hayden Lee的网络A-Frame,使用WebRTC和服务器。这是一个故障,我们可以重新混合开始:https://glitch.com/~networked-aframe

&#13;
&#13;
<script src="https://aframe.io/releases/0.5.0/aframe.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.5/socket.io.min.js"></script>
<script src="easyrtc/easyrtc.js"></script>
<script src="https://unpkg.com/networked-aframe/dist/networked-aframe.min.js"></script>
<script>
  function onConnect() {
    NAF.entities.createAvatar('#avatar-template', '0 1.6 0', '0 0 0');
  }
</script>

<a-scene network-scene>
  <a-assets>
    <script id="avatar-template" type="text/html">
      <a-sphere color="black"></a-sphere>
    </script>
  </a-assets>

  <a-box position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9"></a-box>
  <a-sphere position="0 1.25 -5" radius="1.25" color="#EF2D5E"></a-sphere>
  <a-cylinder position="1 0.75 -3" radius="0.5" height="1.5" color="#FFC65D"></a-cylinder>
  <a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
  <a-sky color="#ECECEC"></a-sky>
</a-scene>
&#13;
&#13;
&#13;

另一个选项是http://lance.gg/,一个实时多人游戏服务器。它提供了一个基于Node.JS的可扩展服务器,游戏逻辑运行在该服务器上,以及一个客户端库,它将客户端的游戏状态与服务器游戏状态同步。为了给每个连接的客户端提供流畅的视觉体验,Lance实现了高效的网络方法,位置插值和外推,用户输入协调,阴影对象,物理和伪物理移动,自动处理网络尖峰。

较早的选项是https://github.com/ngokevin/kframe/tree/master/components/firebase - 使用Firebase实时数据库服务器的Firebase组件,因此您无需托管自己的服务器。