• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Pausing audio on losing window focus (Windows)

J

JaguarSnail

Guest
Hi everyone,

I would like to pause my game's background music once the user makes the window inactive, and resume it when it gets focus again.

I've tried using the os_is_paused() function, but it seems that only returns true for the following single frame.

So i was wondering, is there any way to continuously detect the window's (in)activity?
or to run some code when those events do get fired off?
And if so, how would I achieve this?
 

RangerX

Member
You are near the solution. You don't need more than that one frame to tell the game is not in focus.

if(os_is_paused()) // if no obj pause and game is alt+tabbed out of focus
then
{
audio_pause_all();
}

Then what I suggest is to also pause your game and when its back, have some "press any key" event to continue
 
J

JaguarSnail

Guest
You are near the solution. You don't need more than that one frame to tell the game is not in focus.

if(os_is_paused()) // if no obj pause and game is alt+tabbed out of focus
then
{
audio_pause_all();
}

Then what I suggest is to also pause your game and when its back, have some "press any key" event to continue
Ah yes, just implemented it like that, did the trick for me!

I guess its better practice and perhaps more user-friendly to pause the entire game after all.

Thank you very much! :D
 
Top