Stabilize FPS for JS

This commit is contained in:
Hajime Hoshi 2015-01-08 00:44:41 +09:00
parent 81ed2e3f18
commit 6efb806cc2

View File

@ -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() {