A want to make crossfade effect between two audio. I try Tween.JS for that, but it's not do it smoothly, how I want...
var sound_b_1 = new THREE.PositionalAudio( listener );
sound_b_1.load('mysound.ogg');
sound_b_1.setRefDistance(20);
sound_b_1.setVolume(1);
sound_b_1.autoplay = true;
scene.add(sound_b_1);
var volume = {x : 1}; // tweens not work without object
// using Tween.js
new TWEEN.Tween(volume).to({
x: 0
}, 1000).onUpdate(function() {
sound_b_1.setVolume(this.x);
}).onComplete(function() {
sound_b_1.stop();
}).start();
Hot to do that using Tween or other ways?
I do not see anything wrong with the code you provided, works fine for me, only it is not complete. You need to call
TWEEN.update(time)
in your render/update function:complete code:
This will cause mysound.ogg to start playing at full volume and then interpolated linearly to no volume at all and then stop playing.
If you want another audio clip to start playing you just do the same thing but let the volume start at 0 and interpolate to 1.