如何在A-Frame中重用动画?

时间:2016-09-28 17:52:47

标签: aframe

有没有办法以更漂亮的方式重复使用相同的动画?

<a-entity channel-selection class="channels" mixin="fontplane" material="opacity:0.6">
  <a-animation attribute="material.opacity" begin="fade" to="0"></a-animation>
  <a-animation attribute="material.opacity" begin="unfade" to="0.6"></a-animation>
  <a-entity class="channels" mixin="channelfont" text="text: Channel6">
    <a-animation attribute="material.opacity" begin="fade" to="0"></a-animation>
    <a-animation attribute="material.opacity" begin="unfade" to="0.6"></a-animation>
  </a-entity>
</a-entity>

1 个答案:

答案 0 :(得分:1)

有几种方法。

一:你可以在动画上使用mixins:

<a-mixin id="fade" attribute="material.opacity" begin="fade" to="0"></a-mixin>
<a-mixin id="fade" attribute="material.opacity" begin="unfade" to="0.6"></a-mixin>
<a-entity channel-selection class="channels" mixin="fontplane" material="opacity:0.6">
      <a-animation mixin="fade"></a-animation>
      <a-animation mixin="unfade"></a-animation>

      <a-entity class="channels" mixin="channelfont" text="text: Channel6">
        <a-animation mixin="fade"></a-animation>
        <a-animation mixin="unfade"></a-animation>
      </a-entity>
    </a-entity>

还有animation component with mixinsaframe-mss (mixin stylesheet format),但不幸的是,有一些与mixin相关的错误与可能有多个实例的组件有关。

二:template component也可以正常工作

  <head>
  <title>My A-Frame Scene</title>
  <script src="https://aframe.io/releases/0.3.0/aframe.min.js"></script>
  <script src="https://unpkg.com/ngokevin/aframe-template-component/dist/aframe-template-component.min.js"></script>
</head>

<body>
  <a-scene>
    <a-assets>
      <script id="fadeAnimations" type="text/html">
        <a-animation></a-animation>
        <a-animation></a-animation>
      </script>
    </a-assets>

    <a-entity template="src: #fadeAnimations">
      <a-entity template="src: #fadeAnimations"></a-entity>
    </a-entity>
   </a-scene>