Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Gal Shemesh on Thu 03/08/2023 12:59:28

Title: FadeOut stop playing a sound when player is changing rooms
Post by: Gal Shemesh on Thu 03/08/2023 12:59:28
Hi everyone,

Not sure if it's a bug, but better get a reply that it's not than not reporting at all:

When the 'player.ChangeRoom()' function is used along with the default 'FadeInAndOut' behavior, and a certain sound is set to be played just before changing the room, the sound doesn't play but only after entering the changed room.

For example, I made a click sound for buttons on a main menu screen, and set it to play right before the player.ChangeRoom() function. The click sound however plays either when the fade-out is finished or when the changed room is loaded (I can't tell). But if I set a FadeOut() function manually and afterwrads put the player.ChangeRoom() function then the sound plays correctly upon pressing the button.

Thanks
Title: Re: FadeOut stop playing a sound when player is changing rooms
Post by: RootBound on Thu 03/08/2023 16:08:30
My guess would be that sounds are nonblocking and change room is blocking, so change room would execute first. You could put a Wait(length of sound) in after the sound and before the change room function and see if that works.
Title: Re: FadeOut stop playing a sound when player is changing rooms
Post by: Gal Shemesh on Fri 04/08/2023 10:35:38
Thanks for the reply, @RootBound! Yep, I tried the Wait() function. But unfortunately, it doesn't work very well as I want the sound to play when the FadeOut starts playing, and not to have to wait for the sound to end before it does...
Title: Re: FadeOut stop playing a sound when player is changing rooms
Post by: Khris on Fri 04/08/2023 11:04:14
Sounds like the built-in room fade is hard-coded into the engine in a way that completely halts the main loop, whereas the script command is simply a blocking function like any other which doesn't pause the main loop.

Not sure it qualifies as a bug, but a lot of legacy stuff is somewhat inconsistent internally and should be "fixed" at some point, I guess. Definitely a worthy suggestion for AGS 4.
Title: Re: FadeOut stop playing a sound when player is changing rooms
Post by: RootBound on Fri 04/08/2023 12:45:14
@Gal Shemesh hmm. You could try putting in Wait(1) instead of waiting for the whole sound length, and see if that starts the sound playing before the room starts to fade out?

So it would be

Audioclip.play();
Wait(1);
player.Changeroom();
Title: Re: FadeOut stop playing a sound when player is changing rooms
Post by: Gal Shemesh on Fri 04/08/2023 13:53:56
@RootBound, it's working! 8-0 I thought that 'Wait(1)' will be too short and that the player.ChangeRoom() function will cut it in the middle that I didn't even tried it. Thanks!!  8-)
Title: Re: FadeOut stop playing a sound when player is changing rooms
Post by: RootBound on Fri 04/08/2023 16:22:25
Awesome! Glad it worked!
Title: Re: FadeOut stop playing a sound when player is changing rooms
Post by: Crimson Wizard on Fri 04/08/2023 19:01:56
Quote from: Khris on Fri 04/08/2023 11:04:14Sounds like the built-in room fade is hard-coded into the engine in a way that completely halts the main loop, whereas the script command is simply a blocking function like any other which doesn't pause the main loop.

Not sure it qualifies as a bug, but a lot of legacy stuff is somewhat inconsistent internally and should be "fixed" at some point, I guess.

This is likely not a legacy inconsistency, but, on contrary, a new issue caused by how audio commands "sync" with the new audio subsystem in 3.6.0.
I can swear I already fixed this before, but maybe I fixed it for some other command rather than FadeOut.

@Gal Shemesh, please tell which version of AGS are you using exactly?
Title: Re: FadeOut stop playing a sound when player is changing rooms
Post by: Gal Shemesh on Sat 05/08/2023 10:44:08
Quote from: Crimson Wizard on Fri 04/08/2023 19:01:56Gal Shemesh (https://www.adventuregamestudio.co.uk/forums/profile/goldeng/), please tell which version of AGS are you using exactly?
AGS Editor .NET (Build 3.6.0.50)
v3.6.0, July 2023
Title: Re: FadeOut stop playing a sound when player is changing rooms
Post by: AndreasBlack on Sat 16/09/2023 11:03:46
Quote from: Gal Shemesh on Fri 04/08/2023 10:35:38Thanks for the reply, @RootBound! Yep, I tried the Wait() function. But unfortunately, it doesn't work very well as I want the sound to play when the FadeOut starts playing, and not to have to wait for the sound to end before it does...

In the future, just do like i do. Go into Photoshop Take the biggest black Pencil tool you can get hit your leftmouse. Save the file as the same size as your room is. Either animate it in Photoshop itself fading out or do it in AGS with object transparency and Tween Module. Problem solved, none-blocking! 8-)
Title: Re: FadeOut stop playing a sound when player is changing rooms
Post by: eri0o on Sat 16/09/2023 11:45:11
I think @Crimson Wizard made a change in the engine to fix this, since AGS 3.6.1.6.
Title: Re: FadeOut stop playing a sound when player is changing rooms
Post by: Gal Shemesh on Sat 16/09/2023 14:30:39
Thanks guys. By now I've already implemented a black GUI and made a custom FadeIn and FadeOut functions with it by using transparancy - I don't think I'm going to use the built-in transitions anymore due to their limitations and as they don't give the freedom of control; in my custom fades I can do mostly anything I want, and even choose the amount of transparent value that I wish to make the fade kind of 'jump' to on each screen draw. For example, subtracting transparancy in jumps of '10' with a minor Wait of (3) or so for making a '10 frame like' FadeOut, instead of a smooth fade that drawn on each game cycle.
Title: Re: FadeOut stop playing a sound when player is changing rooms
Post by: eri0o on Sat 16/09/2023 14:51:01
In the sense of screen transitions, I always had a feeling that if it was possible to screenshot the room without the mouse cursor, it would be easy to script your own transition - say you hold the screenshot in a GUI and then instant fade in in the next room, then you can change the transparency of the GUI holding the screenshot to "crossfade" to the next room. If it was possible to screenshot without GUIs too it would be perfect because then you can do things like slide left and slide the new screen from left - or perhaps this is doable with a combination of previous screenshot+viewport... To hack around this in my game I used the fake screen module with some fixes and used it to make my own transitions...
Title: Re: FadeOut stop playing a sound when player is changing rooms
Post by: Crimson Wizard on Sat 16/09/2023 14:58:10
Quote from: eri0o on Sat 16/09/2023 14:51:01In the sense of screen transitions, I always had a feeling that if it was possible to screenshot the room without the mouse cursor, ... If it was possible to screenshot without GUIs too it would be perfect

This was an old feature suggestion for idk how many years, to pass which screen layers to draw in screenshot function.

Since 3.6.1 there are no more game logic updates in the draw routine, afaik, which means it may be safe to call it anytime, passing some "draw on target" and "draw which layers" parameters.
Title: Re: FadeOut stop playing a sound when player is changing rooms
Post by: Cassiebsg on Sun 17/09/2023 20:16:15
QuoteI always had a feeling that if it was possible to screenshot the room without the mouse cursor

But wait, it IS possible to do this.
You just have to hide the mouse cursor and any GUI you don't want in the screenshot, take the screenshot and reactivate everything right after.That's how we take screenshots to use as thumbnails for save games.