如何使用持续时间属性永远循环播放 A-Frame 动画

How to loop A-Frame animation forever using duration attribute

我有一个地球对象,我想使用 A 帧中的动画来旋转它。 我只想让物体永远旋转,但我不知道该怎么做。 下面是我的代码谢谢!

    <a-sphere rotation="45 0 0" position="-44.277 50 -80.933" radius="30" src="images/earth.png" roughness="0.6">

        <a-animation attribute="rotation"
                     easing="linear"
                     dur="10000"
                     to="0 360 0"
                     repeat="indefinite">

        </a-animation>
    </a-sphere>

该代码正确。完成 1 次旋转需要 10,000 毫秒(10 秒),并且会无限期地重复("forever")。我刚刚测试了代码并且它有效。如果 earth.png 纹理没有出现,可能很难看到球体的旋转。例如,如果您在 <a-box> 上使用相同的代码,它会更加明显。

就是说,因为您将 <a-sphere>rotation 沿 x 轴设置为 45,并将 <a-animation> 设置为旋转360y 轴上,它不会以线性方式旋转。

这可以通过添加容器 <a-entity> 元素并在该实体上设置默认 positionrotation 并将其从 <a-sphere> 中移除来解决,这将现在相对于其容器定位。

这是演示:https://codepen.io/dansinni/pen/MVgqxd

请注意,我必须为地球使用不同的纹理。