【问题标题】:A-frame change sound properties onclickA-frame 改变声音属性 onclick
【发布时间】:2021-11-01 07:58:00
【问题描述】:

我在使用 A 帧 (https://aframe.io) 的场景中有一些声音。我的屏幕顶部还有一个按钮按钮。我想知道的是如何做到这一点,当单击按钮时,声音的rolloffFactor 从 1 减少到 0。当前代码:

  <html>
          <head>
            <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
    <script>
    function changeRollOff() {
    /*Code to change factor of roll off here*/
    }
    </script>
        </head>
          <body>
            <a-scene>
            
            <button style="position: fixed; z-index: 10000;" onclick="changeRollOff()"
            >Change RollOffactor</button>    
            
              <a-box position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9"></a-box>
              <a-sphere position="0 1.25 -5" radius="1.25" color="#EF2D5E"></a-sphere>
              <a-cylinder position="1 0.75 -3" radius="0.5" height="1.5" color="#FFC65D"></a-cylinder>
              <a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
        <a-entity id="river" geometry="primitive: plane" material="color: blue"
                  position="-10 0 0" sound="src: url(https://cdn.glitch.com/2ecb29ef-7d11-4ac6-b954-e050a39aa59a%2FCHIPTUNE%2C%20BUT%20FUNKY%20Useful.mp3?v=1630627441361); autoplay: true; rolloffFactor: 1;"></a-entity>
        
              <a-sky color="#ECECEC"></a-sky>
            </a-scene>
          </body>

    </html>

【问题讨论】:

    标签: javascript jquery audio three.js aframe


    【解决方案1】:

    rolloffFactorsound 属性的属性。你可以用element.setAttribute(component, property, new_value)改变它:

    document.getElementById("river").setAttribute("sound", "rolloffFactor", 0);
    

    【讨论】:

    • 对不起,我其实有一个问题。代码通过找到 标签来设置 rolloffFactor,但在我的另一个用途中,我的声音代码实际上被包装在一个实体中,如下所示: 如何修改代码以更改实体的 rollOfffactor 而不是 标签?
    • 如果你想改变networked-audio-source你做同样的事情 - document.getElementById("river").setAttribute("networked-audio-source", "rolloffFactor", 0); 选择器正在寻找具有river id的实体,并更改所需的属性。
    • 我测试了代码,但它不工作。我认为是因为该功能运行良好,因此由于某种原因无法找到音频。是否可以将 rollOffFactor 设置为变量,以便我可以简单地更改变量,从而更改 rollOffFactor?
    猜你喜欢
    • 1970-01-01
    • 2021-01-01
    • 2021-08-13
    • 2019-05-21
    • 1970-01-01
    • 2018-06-03
    • 2019-06-05
    • 2021-08-18
    • 2023-04-01
    相关资源
    最近更新 更多