A-frame 更改声音属性 onclick [英] A-frame change sound properties onclick
本文介绍了A-frame 更改声音属性 onclick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 A-frame (https://aframe.io) 在我的场景中有一些声音.我的屏幕顶部还有一个按钮按钮.我想知道的是如何才能在单击按钮时使声音的 rolloffFactor
从 1 减少到 0.当前代码:
I have some sound in my scene using A-frame (https://aframe.io). I also have a button button at the top of my screen. What I'm wondering is how can I make it so when a button is clicked, the rolloffFactor
of the sound is decreased from 1 to 0. Current code:
<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>
推荐答案
rolloffFactor
是 sound
属性的一个属性.您可以使用 element.setAttribute(component, property, new_value)
:
The rolloffFactor
is a property of the sound
attribute. You can change it with element.setAttribute(component, property, new_value)
:
document.getElementById("river").setAttribute("sound", "rolloffFactor", 0);
这篇关于A-frame 更改声音属性 onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文