首页 > 解决方案 > 通过和 IF 语句(A-Frame 动画混合器)调用动画的正确方法?

问题描述

我目前正在使用 A-Frame 中的动画混合器,并试图在播放特定动画时产生条件(例如 A、B、C 中的动画“B”)。

我不熟悉 Javascript,但我做了几次尝试:

 if(character.getAttribute == character.getAttribute("animation-mixer", {clip: "B"}){
 //  Insert action here 
 }

 if(character == character.setAttribute("animation-mixer", {clip: "B"})){
 //  Insert action here
 };

 if(character.getAttribute("animation-mixer") == {clip: "B"}){
 //  Insert action here
 };

标签: javascriptanimationthree.jsaframe

解决方案


要检索组件数据您应该只使用getAttribute(componentName)

// grabbing the component data object
character.getAttribute("animation-mixer")

// same + accessing the clip property
character.getAttribute("animation-mixer").clip

// checking if the property equals "B"
if (character.getAttribute("animation-mixer").clip === "B") {
   console.log("Its B!")
}

setAttribute()将改变动画:

setAttribute("animation-mixer", "clip", "A")
// or character.setAttribute("animation-mixer", {clip: "B"})
character.getAttribute("animation-mixer").clip // A

推荐阅读