From d216a04cb6d2aafbad654cac4e8515ca57beeac1 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 6 Feb 2017 07:58:14 +0900 Subject: [PATCH] examples/edge: Update to use ImageParts --- examples/edge/main.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/examples/edge/main.go b/examples/edge/main.go index e5dbf60ca..ac5ffd8a6 100644 --- a/examples/edge/main.go +++ b/examples/edge/main.go @@ -38,9 +38,27 @@ var ( angle = 0 ) +type parts struct { + image *ebiten.Image +} + +func (p *parts) Len() int { + return 1 +} + +func (p *parts) Src(index int) (int, int, int, int) { + w, h := p.image.Size() + return 0, 0, w, h / 2 +} + +func (p *parts) Dst(index int) (int, int, int, int) { + w, h := p.image.Size() + return 0, 0, w, h / 2 +} + func update(screen *ebiten.Image) error { if ebiten.IsKeyPressed(ebiten.KeyLeft) { - angle-- + angle += 359 } if ebiten.IsKeyPressed(ebiten.KeyRight) { angle++ @@ -50,6 +68,7 @@ func update(screen *ebiten.Image) error { return err } op := &ebiten.DrawImageOptions{} + op.ImageParts = &parts{colorImage} op.GeoM.Translate(-float64(colorImageWidth)/2, -float64(colorImageHeight)/2) op.GeoM.Rotate(float64(angle) * math.Pi / 180) op.GeoM.Scale(4, 4)