首页 > 解决方案 > A-frame 改变声音属性 onclick

问题描述

我使用 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>

标签: javascriptjqueryaudiothree.jsaframe

解决方案


rolloffFactor是属性的一个属性sound。你可以改变它element.setAttribute(component, property, new_value)

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

推荐阅读