mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
Stop the game when the screen is not active
This commit is contained in:
parent
f2a496b6ad
commit
5e5eea59ce
5
run.go
5
run.go
@ -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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user