Pausing BGM/sounds when game window is defocused?

● ARCHIVED · READ-ONLY
Started by EternalShadow 9 posts View original ↗
  1. 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!
  2. Does this (script under Materials + DLL in System folder) work for you? Everything else would most likely be difficult to achieve.
  3. cremnophobia said:
    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.
  4. 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
  5. 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...
  6. 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!
  7. cremnophobia said:
    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)
  8. 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.
  9. cremnophobia said:
    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!