Pausing BGM/sounds when game window is defocused?

EternalShadow

Veteran
Veteran
Joined
Sep 16, 2012
Messages
5,781
Reaction score
1,041
First Language
English
Primarily Uses
I'm sure we've all had the problem of putting BGM into our games and meticulously timing them to match certain events on the screen that are set to autoplay. However, our efforts are ruined if a player clicks out of the game as the BGM continues to play, thereby mismatching the timing with whatever is happening on screen. Basically, everything goes out of sync.


I vaguely remember there being a 'pause bgm' script or fix, but I cannot remember for the life of me where I saw this, or whether I'm just imagining it. Google isn't much help either, as searches cannot look into files such as restaff - where I have a gut feeling it might be.


Therefore, is there a 'pause bgm when the game window is defocused' script, or am I imagining it? If there isn't one at all, can one be made?


Thanks very much!


Note: For the solution marked as 'best answer' your music files have to be .ogg!
 
Last edited by a moderator:

cremnophobia

Veteran
Veteran
Joined
Dec 10, 2013
Messages
216
Reaction score
97
Primarily Uses
Does this (script under Materials + DLL in System folder) work for you? Everything else would most likely be difficult to achieve.
 

EternalShadow

Veteran
Veteran
Joined
Sep 16, 2012
Messages
5,781
Reaction score
1,041
First Language
English
Primarily Uses
Does this (script under Materials + DLL in System folder) work for you? Everything else would most likely be difficult to achieve.
Unfortunately, it doesn't seem to be what I'm looking for. Defocusing a game isn't the same as pressing a button to pause it. If it could be done when the game is defocused (and not paused ingame), I'm sure a lot of other game makers (and players) would appreciate it, even though it may be a very difficult venture.
 

cremnophobia

Veteran
Veteran
Joined
Dec 10, 2013
Messages
216
Reaction score
97
Primarily Uses
There is no button pressing involved. Or do you want that? You probably should download the project and actually test it. Maybe showing the pause image confused you, so I removed that feature (see attached file).

Project23.zip
 

Attachments

Last edited by a moderator:

EternalShadow

Veteran
Veteran
Joined
Sep 16, 2012
Messages
5,781
Reaction score
1,041
First Language
English
Primarily Uses
Oh, now I understand! I've used it in my project, with success :)


However, one quick thing: is it possible to stop the music restarting when unpaused? My played sound is a BGM triggered by an event.


EDIT: Ok, that is weird. Your second file (without the pause image) makes it pick up where it left off!


EDIT: Tearing my hair out now xD I can't seem to replicate the effect on the one with no pause image, the music just keeps restarting...
 
Last edited by a moderator:

cremnophobia

Veteran
Veteran
Joined
Dec 10, 2013
Messages
216
Reaction score
97
Primarily Uses
Make sure it isn't just the fade-in confusing you. Try it with another BGM (or a song with vocals) with more variation. I had to do the same.


Use the script from my previous post in this thread. Or do you want a pause image to be shown? I can add it back!
 

EternalShadow

Veteran
Veteran
Joined
Sep 16, 2012
Messages
5,781
Reaction score
1,041
First Language
English
Primarily Uses
Make sure it isn't just the fade-in confusing you. Try it with another BGM (or a song with vocals) with more variation. I had to do the same.


Use the script from my previous post in this thread. Or do you want a pause image to be shown? I can add it back!
The music I'm using has a lot of variation, so I know it's not the fadein.


I was saying that the one without the pause image picks up where it left off, but the one with the pause image doesn't. (On your files - the music is the same, but there seems to be a difference in how they return to the song)
 

cremnophobia

Veteran
Veteran
Joined
Dec 10, 2013
Messages
216
Reaction score
97
Primarily Uses
The one from this thread is working and the other one (which is now gone anyway) isn't. Right? Does this mean your problem is solved? I'm confused now! :3


By the way, to my knowledge there isn't any other script that can do that. And for previous RGSS versions, it would have been much work. RGSS3 added “replaying”, but with a fade-in.
 

EternalShadow

Veteran
Veteran
Joined
Sep 16, 2012
Messages
5,781
Reaction score
1,041
First Language
English
Primarily Uses
The one from this thread is working and the other one (which is now gone anyway) isn't. Right? Does this mean your problem is solved? I'm confused now! :3


By the way, to my knowledge there isn't any other script that can do that. And for previous RGSS versions, it would have been much work. RGSS3 added “replaying”, but with a fade-in.
Nope. Can't seem to get it to work without it looping back to the very start, which kind of defeats the point.


I'll send you the project so you can look at it and see what I mean.


EDIT: Solved via PM! The music files have to be .ogg!
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,865
Messages
1,017,059
Members
137,575
Latest member
akekaphol101
Top