Adventure Game Studio

AGS Development => Editor Development => Topic started by: Stranga on Tue 30/11/2021 05:21:33

Title: [Feature Suggestion/Request] Default Music/Ambience option in room properties.
Post by: Stranga on Tue 30/11/2021 05:21:33
Not sure if this has been mentioned before but I thought it may be nice to add an option to the room's settings in the editor to select an ambient/music track to play for that room only and stop playing when exiting. It's not a major thing just a suggestion :)

Like somewhere here:
Spoiler
(https://www.newgrounds.com/dump/draw/3bbe596672d65312d77dec608b9f645a)
[close]
Title: Re: [Feature Suggestion/Request] Default Music/Ambience option in room properties.
Post by: Crimson Wizard on Tue 30/11/2021 10:51:49
There have been such setting before, in the older versions of AGS, called "Play music on room load", but it has been removed in favor of using script commands.

Anything automatic (sound start/stop) in the current audio system tends to increase chances of unintended behavior conflicting with script, because it's unclear how to track such sound.
- If there are multiple music channels, how do you find the one where this "room music" is played on?
- If the "room music" was interrupted by something else (another music, e.g. played during an event), should it restart from beginning / restart from the same position / not restart at all?
- If the "room music" was stopped by a script command, then run again by a script command, should it be considered "same" music or a different one that engine should not stop on room exit now?

If there were a concept of "sound instances", where a playback is an object, that is explicit, may be addressed and tracked, that perhaps would be simplier to handle.




Note that it's relatively simple to script such system for your own game case. Imagine you add a custom property to rooms, called "RoomMusic", you may then use on_event in a global script to catch room enter/leave events and handle this "room music", for example:
Code (ags) Select

AudioChannel *roomMusic;

function on_event (EventType event, int data) {
    if (event == eEventEnterRoomBeforeFadein) {
        int music = Room.GetProperty("RoomMusic");
        if (music >= 0) {
             roomMusic = Game.AudioClips[music].Play();
        }
    } else if (event == eEventLeaveRoom) {
        int music = Room.GetProperty("RoomMusic");
        if (music >= 0) {
             Game.AudioClips[music].Stop();
        }
    }
}
Title: Re: [Feature Suggestion/Request] Default Music/Ambience option in room properties.
Post by: Stranga on Wed 01/12/2021 10:29:12
Thanks for the tip CW! I'll definitely put it to good use :)
Title: Re: [Feature Suggestion/Request] Default Music/Ambience option in room properties.
Post by: Crimson Wizard on Wed 24/01/2024 05:27:56
Request closed, as not intended.