mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
parent
ab41cbadaa
commit
a1e65a5e90
@ -33,27 +33,32 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
count int
|
|
||||||
gophersImage *ebiten.Image
|
gophersImage *ebiten.Image
|
||||||
)
|
)
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
type Game struct {
|
||||||
count++
|
count int
|
||||||
|
}
|
||||||
|
|
||||||
if ebiten.IsDrawingSkipped() {
|
func (g *Game) Update(screen *ebiten.Image) error {
|
||||||
|
g.count++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Game) Draw(screen *ebiten.Image) {
|
||||||
// Center the image on the screen.
|
// Center the image on the screen.
|
||||||
w, h := gophersImage.Size()
|
w, h := gophersImage.Size()
|
||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
op.GeoM.Translate(float64(screenWidth-w)/2, float64(screenHeight-h)/2)
|
op.GeoM.Translate(float64(screenWidth-w)/2, float64(screenHeight-h)/2)
|
||||||
|
|
||||||
// Rotate the hue.
|
// Rotate the hue.
|
||||||
op.ColorM.RotateHue(float64(count%360) * 2 * math.Pi / 360)
|
op.ColorM.RotateHue(float64(g.count%360) * 2 * math.Pi / 360)
|
||||||
|
|
||||||
screen.DrawImage(gophersImage, op)
|
screen.DrawImage(gophersImage, op)
|
||||||
return nil
|
}
|
||||||
|
|
||||||
|
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
|
||||||
|
return screenWidth, screenHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -72,7 +77,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
gophersImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterDefault)
|
||||||
|
|
||||||
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Hue (Ebiten Demo)"); err != nil {
|
ebiten.SetWindowSize(screenWidth*2, screenHeight*2)
|
||||||
|
ebiten.SetWindowTitle("Hue (Ebiten Demo)")
|
||||||
|
if err := ebiten.RunGame(&Game{}); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user