0
votes

In a-frame using aframe-alongpath-component i would like to count each loop of an animation. I think event movingended is not triggered with a loop?! How can i use alongpath-trigger-activated when element is reaching a-curve-point X (maybe endpoint)?

1

1 Answers

0
votes

My assumption was wrong. With every loop movingended is triggered.

      let ball = document.createElement('a-sphere');
      ball.setAttribute('id', `Ball_${a}`);
      ball.setAttribute('class', 'clickable');
      ball.setAttribute('src', `#tBall_${a}`);
      ball.setAttribute(`alongpath`, `curve: .track${a}; dur: ${pathDuration}; delay: ${startdelay}; loop: true ;`);

      ball.addEventListener("movingended", (e) => {
        console.log("moving ended:" + bad_hits);
        bad_hits++;
      });


So i don't need alongpath-trigger-activated. But to answer my question:

      let track = document.createElement('a-curve');
      track.setAttribute('class', `track${a}`);
      scene.append(track);
...
      let point5 = document.createElement('a-curve-point');
      point5.setAttribute('position', '0 3 -5');
      point5.setAttribute('class', 'trigger');
      point5.addEventListener("alongpath-trigger-activated", () => {
         console.log("point 5 alongpath-trigger-activated");
      });
      track.append(point5);