examples/blocks: Use RunGame

Updates #1111
This commit is contained in:
Hajime Hoshi 2020-04-01 15:57:47 +09:00
parent a70d6a314e
commit 01a1334639
2 changed files with 12 additions and 9 deletions

View File

@ -28,7 +28,11 @@ type Game struct {
input Input input Input
} }
func (g *Game) Update(r *ebiten.Image) error { func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
return ScreenWidth, ScreenHeight
}
func (g *Game) Update(*ebiten.Image) error {
if g.sceneManager == nil { if g.sceneManager == nil {
g.sceneManager = &SceneManager{} g.sceneManager = &SceneManager{}
g.sceneManager.GoTo(&TitleScene{}) g.sceneManager.GoTo(&TitleScene{})
@ -38,10 +42,9 @@ func (g *Game) Update(r *ebiten.Image) error {
if err := g.sceneManager.Update(&g.input); err != nil { if err := g.sceneManager.Update(&g.input); err != nil {
return err return err
} }
if ebiten.IsDrawingSkipped() {
return nil
}
g.sceneManager.Draw(r)
return nil return nil
} }
func (g *Game) Draw(screen *ebiten.Image) {
g.sceneManager.Draw(screen)
}

View File

@ -41,9 +41,9 @@ func main() {
defer pprof.StopCPUProfile() defer pprof.StopCPUProfile()
} }
game := &blocks.Game{} ebiten.SetWindowSize(blocks.ScreenWidth*2, blocks.ScreenHeight*2)
update := game.Update ebiten.SetWindowTitle("Blocks (Ebiten Demo)")
if err := ebiten.Run(update, blocks.ScreenWidth, blocks.ScreenHeight, 2, "Blocks (Ebiten Demo)"); err != nil { if err := ebiten.RunGame(&blocks.Game{}); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }