【问题标题】:Play sound component with animation using A-Frame使用 A-Frame 播放带有动画的声音组件
【发布时间】:2016-12-27 23:14:01
【问题描述】:

我正在尝试构建用户驾驶汽车的 A-Frame 场景,并且我需要在汽车开始移动时开始播放汽车的声音。例如:

<a-collada-model id="car" src="#car-dae" position="-0.7 0 -100" rotation="0 90 0">
  <a-animation attribute="position"
         dur="7000"
         begin="model-loaded"
         fill="forwards"
         to="-0.7 0 20"
         repeat="0"
  ></a-animation>
</a-collada-model>

我可以在动画上添加声音组件吗?如果没有,我应该如何让声音与动画同时播放?我尝试将声音组件放在 collada 模型上并给它一个on:model-loaded(与动画相同的事件),但这从未播放过声音。事实上,我似乎能够播放声音的唯一方法是使用自动播放。有什么想法吗?

如果有帮助,我的所有代码都在 carChase.html 下的这个 git repo 中

https://github.com/zeekw/aFrameTests

【问题讨论】:

  • 将 sound="src: #car-sound; autoplay: true; volume: 10" 添加到 collada 模型实体就可以了。试试看。它与汽车的运动很好地同步。
  • @thoragio 是什么让它与汽车的运动同步?
  • 好吧,当我用上面描述的声音属性加载它时,汽车的运动和声音似乎很同步。 IOW,你看到地平线上的汽车向你移动,随着它越来越近,发动机的声音越来越大,直到它从你的正下方经过。
  • @thoragio ,但根据用户的互联网连接和 gpu,汽车可能会在不同的时间开始移动
  • a-asset 标签中有声音和模型,因此 A-Frame 会在渲染场景之前先加载它们。见:aframe.io/docs/0.4.0/core/asset-management-system.html

标签: aframe webvr


【解决方案1】:

您是否尝试将声音组件放在模型上,或者作为它的子级?

<a-collada-model src="#car-dae" sound="on: model-loaded; src: #car-sound">

【讨论】:

  • @ngokevin on: model-loaded 在我尝试时不会播放声音,但 autoplay: true 会。
  • 好的,作为一种变通方法,你可以手动给模型添加一个JS事件监听器,然后像el.components.sound.playSound()一样播放声音。想提出问题?
猜你喜欢
  • 1970-01-01
  • 2019-05-21
  • 2018-06-03
  • 1970-01-01
  • 1970-01-01
  • 2014-01-02
  • 2021-09-09
  • 1970-01-01
  • 2019-09-29
相关资源
最近更新 更多