Pause music when lost window focus
This commit is contained in:
parent
be8447519f
commit
80ec8ff039
12
src/main.c
12
src/main.c
|
@ -100,6 +100,18 @@ int main(int argc, char *argv[])
|
|||
case SDL_QUIT:
|
||||
exit(0);
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event)
|
||||
{
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
musicSetPlaying(1);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
musicSetPlaying(0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ extern void saveGame(void);
|
|||
extern void initCredits(void);
|
||||
extern void doTrophyAlerts(void);
|
||||
extern void drawTrophyAlert(void);
|
||||
extern void musicSetPlaying(int playing);
|
||||
|
||||
App app;
|
||||
Colors colors;
|
||||
|
|
|
@ -56,6 +56,21 @@ void stopMusic(void)
|
|||
Mix_HaltMusic();
|
||||
}
|
||||
|
||||
void musicSetPlaying(int playing)
|
||||
{
|
||||
if (music != NULL)
|
||||
{
|
||||
if (playing)
|
||||
{
|
||||
Mix_ResumeMusic();
|
||||
}
|
||||
else
|
||||
{
|
||||
Mix_PauseMusic();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void playSound(int id)
|
||||
{
|
||||
Mix_PlayChannel(-1, sounds[id], 0);
|
||||
|
|
Loading…
Reference in New Issue