From 5e5eea59ce50a17180aefda6b74f50e5a282ef77 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 21 Feb 2015 22:19:03 +0900 Subject: [PATCH] Stop the game when the screen is not active --- run.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/run.go b/run.go index 8e94116c4..d87fe70d2 100644 --- a/run.go +++ b/run.go @@ -42,6 +42,7 @@ func CurrentFPS() float64 { // // The given function f is guaranteed to be called 60 times a second // even if a rendering frame is skipped. +// f is not called when the screen is not shown. func Run(f func(*Image) error, width, height, scale int, title string) error { runContext.running = true defer func() { @@ -95,6 +96,10 @@ func Run(f func(*Image) error, width, height, scale int, title string) error { return nil } now := ui.Now() + // If gameTime is too old, we assume that screen is not shown. + if int64(5*time.Second/60) < now-gameTime { + gameTime = now + } for gameTime < now { gameTime += int64(time.Second / 60)