Hi all, hope everyone is well.
I once again humbly ask for assistance. Any pointers are helpful.
One of the items in my game is a magic flute (highly original, I know.)
When the flute inventory item is used, it plays a sound effect. I would like the background music to pause while the sound effect plays, and background music resumes when the sound effect is finished.
With my limited scripting knowledge so far, I am able to stop the background music, play the sound effect, and then play one specified background music after. However, this does not accomplish the goal since most rooms have different music.
It would be the most fun for the player if they could use the flute and play the little melody any time, and have whichever room's music pause and resume/restart... Even if it is not in the room where the flute makes something happen.
Can any good wizards of a certain hue, or anyone else, help nudge me in the right direction?
Much appreciated & happy creating to all
To pause/resume your background music, using an audio channel will do.
Yes, like arjOn said you can create an audio channel in your global variables and give it a name, like BGM.
Then you'll have to start your background music like : BGM = aMymusic.Play();
Then, when you click on the flute to start the tune, you can write:
BGM.Stop(); or BGM.Volume = 0;
Depending on how you do things, you might need a timer that's as long as the tune before restarting the background music/ turn the volume back up.
Isn't there a setting where you can specify how much the background music's volume is lowered while AudioClips are played? Or does that only apply to voice speech?
I looked through the manual but couldn't find it.
Quote from: Khris on Sun 30/03/2025 13:50:33Isn't there a setting where you can specify how much the background music's volume is lowered while AudioClips are played? Or does that only apply to voice speech?
This is only affected by speech.
Quote from: Rik_Vargard on Sun 30/03/2025 10:44:20Depending on how you do things, you might need a timer that's as long as the tune before restarting the background music/ turn the volume back up.
Another option is to check the sound playback state, to see when it stops playing (AudioChannel.IsPlaying).
If the idea is to change music volume for the particular sound only, then the easiest way would be to store the returned AudioChannel in a separate global variable, then keep testing it in rep-exec.
Example:
// where you run the sound
FluteChannel = aFlute.Play(); // starts playing flute and saves its channel in a variable
BGM.Pause(); // pause the music
function repeatedly_execute_always()
{
if (FluteChannel != null)
{
if (!FluteChannel.IsPlaying)
{
FluteChannel = null;
BGM.Resume();
}
}
}
Couldn't one simply play the flute sound via voice speech though? Like
player.Say("&123");
Thank you all! That solves that. Greatly appreciated.
Quote from: Khris on Sun 30/03/2025 14:22:14Couldn't one simply play the flute sound via voice speech though? Like
player.Say("&123");
Hmm in such case there's Game.PlayVoiceClip, if one wants to avoid character speech animation and text:
https://adventuregamestudio.github.io/ags-manual/Game.html#gameplayvoiceclip