【发布时间】:2020-11-16 17:39:54
【问题描述】:
我正在尝试找到一种有效的方法来在播放一个动画“X”次后一个接一个地执行动画。
由于通过数组选择随机动画,我的动画无法编译成一个较长的 GTLF/GLB 动画。
我遇到的问题是完成后重复此代码。
这是我目前的做法:
// Counter (to determine when to execute multiple animations sequentially)
var counter = 0;
// No. counter needs to reach. Between 1 & 3 loops
function randomIntFromInterval(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
};
var countertrigger = randomIntFromInterval(1,3);
// Default animation for Character
character.setAttribute("animation-mixer", {clip: "animationA"});
character.addEventListener('animation-loop', function () {
if (character.getAttribute = character.getAttribute("animation-mixer", {clip: "animationA"})){
counter++;
if (counter === countertrigger){
character.setAttribute("animation-mixer", {clip: "animationB"});
character.addEventListener('animation-finished',function() {
if (character.getAttribute("animation-mixer").clip === "animationB"){
character.setAttribute("animation-mixer", {clip: "animationC"});
character.addEventListener('animation-finished',function() {
if (character.getAttribute("animation-mixer").clip === "animationC"){
character.setAttribute("animation-mixer", {clip: "animationA"});
// Resets idle counter
counter = 0;
// Resets/randomises the no. loops before next multiple animations execute
countertrigger = randomIntFromInterval(1,3);
};
});
};
});
};
};
});
【问题讨论】:
-
每个
animation-loop都会创建新的侦听器。你想要一个循环(1/3)循环的 A,然后是 B->C?你有一个简单的模型来测试动画状态吗?
标签: javascript animation three.js aframe