mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
Call game.Update
This commit is contained in:
parent
5236bb92a4
commit
d4ef198c6d
@ -20,6 +20,7 @@ import "C"
|
|||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
"github.com/hajimehoshi/go-ebiten/graphics"
|
"github.com/hajimehoshi/go-ebiten/graphics"
|
||||||
)
|
)
|
||||||
@ -33,7 +34,7 @@ func (game *DemoGame) Update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (game *DemoGame) Draw(g *graphics.GraphicsContext, offscreen *graphics.Texture) {
|
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
|
//export display
|
||||||
@ -75,11 +76,26 @@ func main() {
|
|||||||
C.setDisplayFunc()
|
C.setDisplayFunc()
|
||||||
C.setIdleFunc()
|
C.setIdleFunc()
|
||||||
|
|
||||||
|
ch := make(chan bool, 1)
|
||||||
game := &DemoGame{}
|
game := &DemoGame{}
|
||||||
device = graphics.NewDevice(screenWidth, screenHeight, screenScale,
|
device = graphics.NewDevice(screenWidth, screenHeight, screenScale,
|
||||||
func(g *graphics.GraphicsContext, offscreen *graphics.Texture) {
|
func(g *graphics.GraphicsContext, offscreen *graphics.Texture) {
|
||||||
|
ch<- true
|
||||||
game.Draw(g, offscreen)
|
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()
|
C.glutMainLoop()
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,6 @@ func (device *Device) Update() {
|
|||||||
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_NEAREST)
|
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_NEAREST)
|
||||||
g.SetOffscreen(device.offscreenTexture)
|
g.SetOffscreen(device.offscreenTexture)
|
||||||
g.Clear()
|
g.Clear()
|
||||||
// TODO: lock this!
|
|
||||||
device.drawFunc(g, device.offscreenTexture)
|
device.drawFunc(g, device.offscreenTexture)
|
||||||
g.flush()
|
g.flush()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user