javascript - 通过和 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
};
解决方案
要检索组件数据您应该只使用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
推荐阅读
- spring - 为什么我的 REST 端点没有公开?虽然应用程序运行成功。有人能指出我的错误吗
- python - 如何在 MXNet 中设置 tensor dtypes = int64 的默认值?
- reactjs - 枚举的对象文字的打字稿类型?
- reactjs - 按执行顺序反应类组件问题
- email - bluehost 在本地主机上运行良好但未发送我的电子邮件的问题
- python - 遇到 ModuleNotFoundError: No module named 'matplotlib' 尽管 # All requested packages already installed
- python - 如何检测低分辨率形状的角落?
- docker - 如果依赖容器运行状况检查导致不健康,请不要启动依赖容器
- android - Mokito 比较失败
- python - 类不在python中打印更新的参数