mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
examples/edge: Update to use ImageParts
This commit is contained in:
parent
6929c70c06
commit
d216a04cb6
@ -38,9 +38,27 @@ var (
|
|||||||
angle = 0
|
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 {
|
func update(screen *ebiten.Image) error {
|
||||||
if ebiten.IsKeyPressed(ebiten.KeyLeft) {
|
if ebiten.IsKeyPressed(ebiten.KeyLeft) {
|
||||||
angle--
|
angle += 359
|
||||||
}
|
}
|
||||||
if ebiten.IsKeyPressed(ebiten.KeyRight) {
|
if ebiten.IsKeyPressed(ebiten.KeyRight) {
|
||||||
angle++
|
angle++
|
||||||
@ -50,6 +68,7 @@ func update(screen *ebiten.Image) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
|
op.ImageParts = &parts{colorImage}
|
||||||
op.GeoM.Translate(-float64(colorImageWidth)/2, -float64(colorImageHeight)/2)
|
op.GeoM.Translate(-float64(colorImageWidth)/2, -float64(colorImageHeight)/2)
|
||||||
op.GeoM.Rotate(float64(angle) * math.Pi / 180)
|
op.GeoM.Rotate(float64(angle) * math.Pi / 180)
|
||||||
op.GeoM.Scale(4, 4)
|
op.GeoM.Scale(4, 4)
|
||||||
|
Loading…
Reference in New Issue
Block a user