examples/wheel: Use RunGame (#1182)

Updates #1111
This commit is contained in:
loig 2020-06-07 12:23:25 +02:00 committed by GitHub
parent 6d779965f9
commit e117086ca1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,33 +37,38 @@ const (
screenHeight = 240 screenHeight = 240
) )
var ( type Game struct {
x = 0.0 x float64
y = 0.0 y float64
) }
func update(screen *ebiten.Image) error { func (g *Game) Update(screen *ebiten.Image) error {
dx, dy := ebiten.Wheel() dx, dy := ebiten.Wheel()
x += dx g.x += dx
y += dy g.y += dy
return nil
if ebiten.IsDrawingSkipped() { }
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(x, y) op.GeoM.Translate(g.x, g.y)
op.GeoM.Translate(screenWidth/2, screenHeight/2) op.GeoM.Translate(screenWidth/2, screenHeight/2)
screen.DrawImage(pointerImage, op) screen.DrawImage(pointerImage, op)
ebitenutil.DebugPrint(screen, ebitenutil.DebugPrint(screen,
fmt.Sprintf("Move the red point by mouse wheel\n(%0.2f, %0.2f)", x, y)) fmt.Sprintf("Move the red point by mouse wheel\n(%0.2f, %0.2f)", g.x, g.y))
}
return nil func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
return screenWidth, screenHeight
} }
func main() { func main() {
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Wheel (Ebiten Demo)"); err != nil { g := &Game{x: 0.0, y: 0.0}
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
ebiten.SetWindowTitle("Wheel (Ebiten Demo)")
if err := ebiten.RunGame(g); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }