Stop the game when the screen is not active

This commit is contained in:
Hajime Hoshi 2015-02-21 22:19:03 +09:00
parent f2a496b6ad
commit 5e5eea59ce

5
run.go
View File

@ -42,6 +42,7 @@ func CurrentFPS() float64 {
// //
// The given function f is guaranteed to be called 60 times a second // The given function f is guaranteed to be called 60 times a second
// even if a rendering frame is skipped. // 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 { func Run(f func(*Image) error, width, height, scale int, title string) error {
runContext.running = true runContext.running = true
defer func() { defer func() {
@ -95,6 +96,10 @@ func Run(f func(*Image) error, width, height, scale int, title string) error {
return nil return nil
} }
now := ui.Now() 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 { for gameTime < now {
gameTime += int64(time.Second / 60) gameTime += int64(time.Second / 60)