在 a-frame-alongpath-component 上控制动画

Control animation on the a-frame-alongpath-component

问题是我想在开始时禁用自动播放动画。

我想为什么不开始这句话

AFRAME.registerComponent('track1', { <

代码越来越乱,我正在尝试找出 #track1 上的函数 'remove' 和“播放”。

单击“动画按钮”可在 #track1 上设置功能 'play'。

aframe-along-component.js 中的代码 'triggers:a-curve-point' 总是会触发动画,因此很快就会建立一条曲线,如 #track1。

AFRAME.registerComponent('alongpath', {

//dependencies: ['curve'],

schema: {
    curve: {default: ''},
    triggers: {default: 'a-curve-point'},
    triggerRadius: {type: 'number', default: 0.01},
    dur: {default: 1000},
    delay: {default: 0},
    loop: {default: false},
    rotate: {default: false},
    resetonplay: {default:true}
},

init: function () { <

The link to Glitch

虽然最好用一些流量控制来扩展 alongpath 组件,但您可以在没有它的情况下实现 play / stop / reset 功能。

  • 动态添加组件模拟play()

  • 调用其.reset()方法重置动画:

    AFRAME.registerComponent("track1", {
      init: function() {
        var box = document.querySelector("a-box");
        document.querySelector(".enter").addEventListener("click", e => {
    
          if (box.components.alongpath) {
            // if the component is attached - reset
            box.components.alongpath.reset();
          } else {
            // otherwise attach it
            box.setAttribute("alongpath", "curve", "#track1");
          }
        });
      }
    });
    

看看here(点鱼看出处)