Merge pull request #21 from cxong/missiles

Pause music when lost window focus
This commit is contained in:
Stephen J Sweeney 2017-05-14 14:03:09 +01:00 committed by GitHub
commit b04febffec
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);