lifecycleStateChange method
This is the lifecycle state change hook; every time the game is resumed, paused or suspended, this is called.
The default implementation does nothing; override to use the hook. Check AppLifecycleState for details about the events received.
Implementation
@override
void lifecycleStateChange(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.resumed:
// On resume, if active overlay is not PauseMenu,
// resume the engine (lets the parallax effect play).
if (!(overlays.isActive(PauseMenu.id)) &&
!(overlays.isActive(GameOverMenu.id))) {
resumeEngine();
}
break;
case AppLifecycleState.paused:
case AppLifecycleState.detached:
case AppLifecycleState.inactive:
case AppLifecycleState.hidden:
// If game is active, then remove Hud and add PauseMenu
// before pausing the game.
if (overlays.isActive(Hud.id)) {
overlays.remove(Hud.id);
overlays.add(PauseMenu.id);
}
pauseEngine();
break;
}
super.lifecycleStateChange(state);
}