Pause music when lost window focus

This commit is contained in:
Cong 2017-05-14 14:47:54 +10:00
parent be8447519f
commit 80ec8ff039
3 changed files with 28 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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);