Playing multiple sounds and background music at a time using Haxe script

Hello guys, I am working on a Bullet hell game and I want to play multiple audio files at a time. I want to play the background music at a low volume, gun and explosion sounds simultaneously. However, the problem is that, when the background music is playing, the gun and explosion sounds get muted and cannot be heard. Is there a way to get around this using a Haxe script.

@ArmoredDP Hi,

In general, it should be possible to play multiple audios at the same instance. I wrote a simple code to test if it works in Haxe, and it does

Here was my script:

package arm;

import iron.system.Input;
import iron.data.Data;
import kha.Sound;
import iron.system.Audio;

class DualAudioScript extends iron.Trait {

	var sound1:Sound;

	public function new() {
		super();

		notifyOnInit(function() {

			Data.getSound("loop_ambient_01.wav", onLoadSound); //load background
			Data.getSound("beep_01.wav", storeAudio); //load gun beep

		});

		notifyOnUpdate(function() {

			if(Input.getKeyboard().started('space'))
			{
				var aud1 = Audio.play(sound1, false); //play gun beep on spacebar
			}
			
		});
	}

	public function onLoadSound(sound:Sound)
	{
		var aud2 = Audio.play(sound,true); //Play background in loop from game start
	}

	public function storeAudio(sound:Sound)
	{
		sound1 = sound;
	}
}

I may have misunderstood your question, in that case, please elaborate a bit.

Best,
QC

4 Likes

@QuantumCoderQC Thank you very much for your reply, your code worked wonderfully. I managed to customise it according to my needs and it was awesome. Thank you very much, you answered exactly where I needed help.

2 Likes