如何调整AFrame中a-entity实体animation组件的dur属性修改动画速度
AFrame子实体动画dur属性调整方案
首先明确你要修改的子实体动画类型,两种常见场景操作如下:
场景1:修改子实体现有鼠标移入触发的动画dur为4000
你提供的现有代码里子实体的animation__mouseenter命名动画,当前dur已经是4000,如果需要调整为其他值或者确认配置,直接修改这个属性内部的dur参数即可,父子实体的动画相互独立,父级30000ms的循环动画不会影响子级动画的时长配置。
修改后的完整代码如下:
<a-entity class="rota" id="duck1" color="#fdfd96" scale="0.1 0.1 .1" position="2 0 -7" animation="property: rotation; to:0 -360 0; loop:true; easing:linear; dur:30000"> <a-entity class="rota" color="#F0FFF0" gltf-model="spaceship.glb" animation__mouseenter="property: rotation; to:0 360 0; easing:linear; dur:4000; startEvents: mouseenter" position="20 0 -10" scale="2 3 3" collison-check="el: #otherduck; radius: 0.15; other-radius: 0.15;"> </a-entity> </a-entity>
场景2:给子实体新增自动循环的默认动画,设置dur为4000
如果你需要子实体和父实体一样,加载后就自动循环播放旋转动画,不需要鼠标触发,直接给子实体新增不带事件后缀的animation属性即可,子级动画会和父级30000ms的动画叠加运行:
<a-entity class="rota" id="duck1" color="#fdfd96" scale="0.1 0.1 .1" position="2 0 -7" animation="property: rotation; to:0 -360 0; loop:true; easing:linear; dur:30000"> <a-entity class="rota" color="#F0FFF0" gltf-model="spaceship.glb" animation="property: rotation; to:0 -360 0; loop:true; easing:linear; dur:4000" animation__mouseenter="property: rotation; to:0 360 0; easing:linear; dur:4000; startEvents: mouseenter" position="20 0 -10" scale="2 3 3" collison-check="el: #otherduck; radius: 0.15; other-radius: 0.15;"> </a-entity> </a-entity>
注意:AFrame中同一实体的多个动画需要用不同的命名后缀区分(比如
animation__mouseenter、animation__auto),避免属性覆盖。
内容的提问来源于stack exchange,提问作者Psychonaut007
相关产品推荐
相关产品推荐

