javascript - A帧动画

标签 javascript aframe

我已经尝试了太多但结果相同,当自定义事件触发 a 帧中的动画时,它以相同的方式从 (x,y,z) 播放该动画到 (x',y',z')从 (x'',y'',z'') 到 (x',y',z') 我试过 a-animation 属性,但从来没有找到解决方案!

                  <html>
              <body>
                <script src="https://aframe.io/releases/0.2.0/aframe.min.js"></script>
                <script src="https://rawgit.com/ngokevin/aframe-layout-component/master/dist/aframe-layout-component.min.js"></script>
                <a-scene>
                  <a-entity id="gallery" layout="type: line; margin: 1.2" position="0 0 3">

                    <a-plane id="one" color="#CCC" look-at="[camera]"></a-plane>
                    <a-plane id="two" color="#CCC" look-at="[camera]"></a-plane>
                    <a-plane id="three" color="#CCC" look-at="[camera]"></a-plane>
                    </a-entity>
              <!--camera & env -->
                <a-camera position="0 0 4" id="camera">
                  <a-entity cursor="fuse: true; maxDistance: 30; timeout: 500"
                    position="0 0 -.6"
                    scale=".01 .01 .01"
                    geometry="primitive: ring"
                    material="color: green; shader: flat">
              </a-entity>
              <a-animation attribute="position"
                begin="one"
                to="0 0 4"
                dur="1000"
                fill="forwards"
                easing="ease-in-out-cubic"></a-animation>
                <a-animation attribute="position"
                  begin="two"
                  to="1 0 4"
                  dur="1000"
                  fill="forwards"
                  easing="ease-in-out-cubic"></a-animation>
                <a-animation  attribute="position"                 begin="three"                                                          dur="1000"                                                            fill="forwards"
              to="2 0 4"
              easing="ease-in-out-cubic"></a-animation>

                </a-camera>

                <a-sky color="#ECECEC"></a-sky>
                <a-light type="directional" color="#fff" intensity="0.2" position="-1 2 1"></a-light>
                <a-light type="ambient" color="#fff"></a-light>
              </a-scene>
              </body>
              </html>

Javascript:

    var one =     document.querySelector('#one');
    var two = document.querySelector('#two');
    var three = document.querySelector('#three');
    one.addEventListener('click', function () {
              camera.emit('one');
              });
    two.addEventListener('click', function () {
              camera.emit('two');
                        });

    three.addEventListener('click', function () {
              camera.emit('three');
                });

这是 codepen 中的测试: http://codepen.io/anon/pen/OXaoKg

最佳答案

这里的部分问题是重复触发点击。我们可以这样控制:

var at = "one";

one.addEventListener('click', function () {
  if( at !== "one") {
    at = "one";
    camera.emit('one');
  }
});
two.addEventListener('click', function () {
  if( at !== "two") {
    at = "two";
    camera.emit('two');
  }
});

three.addEventListener('click', function () {
  if( at !== "three") {
    at = "three";
    camera.emit('three');
  }
 });

http://codepen.io/akademy/pen/MjMZVJ

关于javascript - A帧动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38851261/

相关文章:

javascript - 将值绑定(bind)到对象属性、对象、数组、AngularJS

javascript - 如何调用具有不同值的函数而不在每次渲染上重新创建新的箭头函数?

javascript - 我怎样才能将 2 次按键作为一次响应来响应?

aframe - 如何在 A-Frame 中实现多用户?

javascript - 如何使用 Qunit 对 A-Frame 组件进行单元测试?

aframe - 如何在帧中获得渲染器

javascript - 如何通过 Google map 地理编码而不是经度和纬度使用地址

javascript - 使用解析器从 javascript 中提取私有(private)函数

aframe - AR.JS 无法使用仅 3D 的 NFT 获取视频或图片

aframe - 如何隐藏 A-Frame 的 VR 模式/护目镜图标?