Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: rmonic79 on Sat 29/07/2017 16:06:13

Title: Music volume overlay. [SOLVED]
Post by: rmonic79 on Sat 29/07/2017 16:06:13
hi guys there is any fast way to have always system music volume in overlay. I need it for testing purpose.
Title: Re: Music volume overlay.
Post by: Slasher on Sat 29/07/2017 16:34:28
If I understand you correctly: you could always use a slider on a gui that sets system music volume.
Title: Re: Music volume overlay.
Post by: Khris on Sat 29/07/2017 19:16:35
Put a label on a GUI, then update its .Text in repeatedly_execute_always.
Title: Re: Music volume overlay.
Post by: rmonic79 on Sat 29/07/2017 20:43:48
I didn't find a Way to get system music volume, there is a specific command?
Title: Re: Music volume overlay.
Post by: horusr on Sat 29/07/2017 21:01:34
QuoteSeeking and changing volume
So, how do you change a sound once it is playing? Well, there are no methods on the Audio Clip to do this, because you might be playing two copies of the same sound at once, and then AGS wouldn't know which one you wanted to access. That's where Audio Channels come to the rescue.

When you use the Play() command, AGS returns to you an AudioChannel* instance representing the channel on which the sound is playing. You can store this to a global variable and access it later on. For example:


AudioChannel* chan = aExplosion.Play();
chan.Volume = 20;

This will start the aExplosion audio clip playing, and then change its volume to 20%.

I think manual only says this. System.Volume controls all sounds I think.
Title: Re: Music volume overlay.
Post by: rmonic79 on Sat 29/07/2017 21:08:24
Quote from: horusr on Sat 29/07/2017 21:01:34
Quotestatic int System.Volume;

Gets/sets the overall system volume, from 0 to 100. This is the master volume control, that affects all audio in the game. You would usually attach this to a GUI Slider to enable the player to control the volume from some sort of Control Panel GUI.

o thanks i was searching in Game.
But he gets the overall system volume and i need to get music volume.
Title: Re: Music volume overlay.
Post by: Crimson Wizard on Sat 29/07/2017 21:15:03
It is Game.SetAudioTypeVolume.

Code (ags) Select

Game.SetAudioTypeVolume(eAudioTypeMusic, 20, eVolExistingAndFuture);
Title: Re: Music volume overlay.
Post by: rmonic79 on Sat 29/07/2017 21:18:39
Quote from: Crimson Wizard on Sat 29/07/2017 21:15:03
It is Game.SetAudioTypeVolume.

Code (ags) Select

Game.SetAudioTypeVolume(eAudioTypeMusic, 20, eVolExistingAndFuture);


i can use it also to get the volume?
Title: Re: Music volume overlay.
Post by: horusr on Sat 29/07/2017 21:29:36
I think you can use a loop to get audio clips and thenif their .Type is eAudioTypeMusic then you can get its channel and get its volume with .Volume option and then set a label's .Text to it...

I will look into how can you do these all.
Title: Re: Music volume overlay.
Post by: rmonic79 on Sat 29/07/2017 21:36:13
i know it can be done with a some coding, i would like to knew if there's was a fast way to do it, cause i have a very short time to finish the build and i have a lot of things to do ;)
Title: Re: Music volume overlay.
Post by: horusr on Sat 29/07/2017 22:07:32
Only took half an hour and I learned a lot of things!

Code (ags) Select
AudioChannel* channel;

function repeadetly_execute()
{
  for (int i; i < System.AudioChannelCount; i++)
  {
    channel = System.AudioChannels[i];
    if (channel.PlayingClip != null && channel.PlayingClip.Type == eAudioTypeMusic)
      Label.Text = String.Format("%d", channel.Volume);
  }
}


This displays volume of current music.
Title: Re: Music volume overlay.
Post by: rmonic79 on Sat 29/07/2017 22:15:21
thanks horusr
Title: Re: Music volume overlay. [SOLVED]
Post by: Crimson Wizard on Sat 29/07/2017 22:59:13
Quote from: rmonic79 on Sat 29/07/2017 21:18:39
Quote from: Crimson Wizard on Sat 29/07/2017 21:15:03
It is Game.SetAudioTypeVolume.

Code (ags) Select

Game.SetAudioTypeVolume(eAudioTypeMusic, 20, eVolExistingAndFuture);


i can use it also to get the volume?


No, but you can simply remember volume you set in your own variable.