为什么我的A-Frame动画不能正确循环播放?

huangapple go评论63阅读模式
英文:

Why aren't my A-Frame animations looping properly?

问题

我正在尝试让这些动画循环播放,但它们只运行一次然后停止。我的代码如下:

<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<a-scene>
    <a-box height="0.1" width="3" depth="7" position="0 3.5 0" color="#964800" rotation="45 0 0" 
    animation__first="property: rotation; from: 45 0 0; to: -45 0 0; dur: 300 startEvents: loaded, animationcomplete__second;"
    animation__second="property: rotation; from: -45 0 0; to: 45 0 0; delay: 500; startEvents: animationcomplete__first;">
        <a-cone radius-bottom="1.5" radius-top="1.5" height="1.5" position="0 .75 2" color="#964800"></a-cone>
    </a-box>
</a-scene>

我尝试将"first"和"second" 更改为 "1" 和 "2",但没有变化,我还尝试更改"loaded"和"animationcomplete"的顺序,同样没有改变。

英文:

I am trying to get these animations to loop, but they only run once each then stop. My code is as follows

&lt;script src=&quot;https://aframe.io/releases/1.2.0/aframe.min.js&quot;&gt;&lt;/script&gt;
&lt;a-scene&gt;
    &lt;a-box height=0.1 width=3 depth=7 position=&quot;0 3.5 0&quot; color=&quot;#964800&quot; rotation=&quot;45 0 0&quot; 
    animation__first=&quot;property:rotation; from:45 0 0; to:-45 0 0; dur:300 startEvents:loaded, animationcomplete__second;&quot;
    animation__second=&quot;property:rotation; from:-45 0 0; to:45 0 0; delay:500; startEvents:animationcomplete__first;&quot;&gt;
        &lt;a-cone radius-bottom=1.5 radius-top=1.5 height=1.5 position=&quot;0 .75 2&quot; color=&quot;#964800&quot;&gt;&lt;/a-cone&gt;
    &lt;/a-box&gt;
&lt;/a-scene&gt;

I've tried changing the first and second to 1 and 2 with no change and I tried changing the order of loaded and animationcomplete which, once again, changed nothing.

答案1

得分: 1

以下是翻译好的部分:

You're missing a semicolon in the first animation (so i guess the startEvents aren't properly parsed at all, and the first animation starts on loaded by default. With the semicolon it works properly:

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-html -->
    <script src="https://aframe.io/releases/1.4.0/aframe.min.js"></script>
    <a-scene>
        <a-box height=0.1 width=3 depth=7 position="0 3.5 -5" color="#964800" rotation="45 0 0" 
               animation__first="property:rotation; from:45 0 0; to:-45 0 0; 
                                 dur:300; startEvents:loaded, animationcomplete__second;"
               animation__second="property:rotation; from:-45 0 0; to:45 0 0; 
                                 delay:500; startEvents: animationcomplete__first;">
            <a-cone radius-bottom=1.5 radius-top=1.5 height=1.5 position="0 .75 2" color="#964800"></a-cone>
        </a-box>
    </a-scene>

<!-- end snippet -->
英文:

You're missing a semicolon in the first animation (so i guess the startEvents aren't properly parsed at all, and the first animation starts on loaded by default. With the semicolon it works properly:

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-html -->

&lt;script src=&quot;https://aframe.io/releases/1.4.0/aframe.min.js&quot;&gt;&lt;/script&gt;
&lt;a-scene&gt;
    &lt;a-box height=0.1 width=3 depth=7 position=&quot;0 3.5 -5&quot; color=&quot;#964800&quot; rotation=&quot;45 0 0&quot; 
           animation__first=&quot;property:rotation; from:45 0 0; to:-45 0 0; 
                             dur:300; startEvents:loaded, animationcomplete__second;&quot;
           animation__second=&quot;property:rotation; from:-45 0 0; to:45 0 0; 
                             delay:500; startEvents: animationcomplete__first;&quot;&gt;
        &lt;a-cone radius-bottom=1.5 radius-top=1.5 height=1.5 position=&quot;0 .75 2&quot; color=&quot;#964800&quot;&gt;&lt;/a-cone&gt;
    &lt;/a-box&gt;
&lt;/a-scene&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年2月19日 12:01:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75497906.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定