From 6efb806cc2f4debd12dc929adb8df3aca74f20f5 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 8 Jan 2015 00:44:41 +0900 Subject: [PATCH] Stabilize FPS for JS --- internal/ui/ui_js.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index e6d7c141c..37301159b 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -21,7 +21,6 @@ import ( "github.com/gopherjs/webgl" "github.com/hajimehoshi/ebiten/internal/opengl" "strconv" - "time" ) var canvas js.Object @@ -32,7 +31,12 @@ func Use(f func(*opengl.Context)) { } func DoEvents() { - time.Sleep(0) + // TODO: requestAnimationFrame is not called when the window is not activated. + ch := make(chan struct{}) + js.Global.Get("window").Call("requestAnimationFrame", func() { + close(ch) + }) + <-ch } func Terminate() {