ebiten/ebiten.go

39 lines
733 B
Go
Raw Normal View History

2013-06-18 17:48:41 +02:00
package ebiten
import (
"time"
"github.com/hajimehoshi/go-ebiten/graphics"
2013-06-19 01:49:54 +02:00
"github.com/hajimehoshi/go-ebiten/graphics/opengl"
2013-06-18 17:48:41 +02:00
"github.com/hajimehoshi/go-ebiten/ui"
)
type Game interface {
Update()
2013-06-19 01:49:54 +02:00
Draw(g graphics.GraphicsContext, offscreen graphics.Texture)
2013-06-18 17:48:41 +02:00
}
2013-06-19 02:22:54 +02:00
func OpenGLRun(game Game, u ui.UI) {
2013-06-18 17:48:41 +02:00
ch := make(chan bool, 1)
2013-06-19 01:49:54 +02:00
device := opengl.NewDevice(
2013-06-18 17:48:41 +02:00
u.ScreenWidth(), u.ScreenHeight(), u.ScreenScale(),
2013-06-19 01:49:54 +02:00
func(g graphics.GraphicsContext, offscreen graphics.Texture) {
2013-06-18 17:48:41 +02:00
ticket := <-ch
game.Draw(g, offscreen)
ch<- ticket
})
go func() {
const frameTime = time.Second / 60
tick := time.Tick(frameTime)
for {
<-tick
ticket := <-ch
game.Update()
ch<- ticket
}
}()
ch<- true
u.Run(device)
}