mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
Call game.Update
This commit is contained in:
parent
5236bb92a4
commit
d4ef198c6d
@ -20,6 +20,7 @@ import "C"
|
||||
import (
|
||||
"image/color"
|
||||
"os"
|
||||
"time"
|
||||
"unsafe"
|
||||
"github.com/hajimehoshi/go-ebiten/graphics"
|
||||
)
|
||||
@ -33,7 +34,7 @@ func (game *DemoGame) Update() {
|
||||
}
|
||||
|
||||
func (game *DemoGame) Draw(g *graphics.GraphicsContext, offscreen *graphics.Texture) {
|
||||
g.Fill(&color.RGBA{R: 0, G: 0, B: 255, A: 255})
|
||||
g.Fill(&color.RGBA{R: 128, G: 128, B: 255, A: 255})
|
||||
}
|
||||
|
||||
//export display
|
||||
@ -75,11 +76,26 @@ func main() {
|
||||
C.setDisplayFunc()
|
||||
C.setIdleFunc()
|
||||
|
||||
ch := make(chan bool, 1)
|
||||
game := &DemoGame{}
|
||||
device = graphics.NewDevice(screenWidth, screenHeight, screenScale,
|
||||
func(g *graphics.GraphicsContext, offscreen *graphics.Texture) {
|
||||
ch<- true
|
||||
game.Draw(g, offscreen)
|
||||
<-ch
|
||||
})
|
||||
|
||||
go func() {
|
||||
const frameTime = time.Second / 60
|
||||
lastTime := time.Now()
|
||||
for {
|
||||
ch<- true
|
||||
game.Update()
|
||||
<-ch
|
||||
time.Sleep(frameTime - time.Since(lastTime))
|
||||
lastTime = time.Now()
|
||||
}
|
||||
}()
|
||||
|
||||
C.glutMainLoop()
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ func (device *Device) Update() {
|
||||
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_NEAREST)
|
||||
g.SetOffscreen(device.offscreenTexture)
|
||||
g.Clear()
|
||||
// TODO: lock this!
|
||||
device.drawFunc(g, device.offscreenTexture)
|
||||
g.flush()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user