#Determining which room is currently in use, and playing a different sound when enteringleaving.
9 messages · Page 1 of 1 (latest)
At the start of any room pretty much
I just need a specific song to be played in the rooms I go between
Well for that instead of all of this array stuff I just have an object that runs a master list function at the start of the room then destroys itself to pick music to play and such.
and the function is one long switch statement
switch(room)
{
case room1:
//play sound ect
break;
case room3:
case room6:
//play sound ect
break;
}
but if you wanna keep the data table, instead of an array a struct might be better
make each var in the struct the name of a room
and you can can find the var with room_get_name.
Also in general, in my game I have a persistent object that handles playing all BGM and fanfair.
Anything that wants to change BGM sends the sound to that object, and it handles checking if it's already playing, and if so ignore the command, if not fade out the last song and play the new one and such.
The current BGM is stored in a var
BGM = audio_play_sound(sound, 1, true);
and you can stop that specific sound instance by going audio_stop_sound(BGM );
So basically if I had a persistent object handle it, every time I would switch rooms I would just have to send the requested sound to that object?
Or function within the object if that makes any more sense.
yeah, persistent objects don't get destroyed at the end of a room.
So you can send it a request at the end of the room and it will just do it.
you can maybe also use globals to keep track of info on songs and such.
But yeah at the start of my game, I create a persistent BGM_player object that never gets destroyed.
I got functions that send requests to that object to play songs, and the object handles checking the incoming track to the current playing one, and all that. Room transitions don't interrupt it.
Alright I’ll have to look into this tomorrow, but one last thing I need cleared up is how do I determine when the room is left?
It's a nice system, I got some more advanced functions too, like fading out the 'main' track to play a secondary track, and then being able to fade back in the original BGM without having to restart it.
for determining that, there are room end events. Or you just stick it wherever your code is to change rooms.