2021-08-18 16:34:51 +10:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/gob"
|
|
|
|
"image"
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Ensure Image satisfies interfaces.
|
|
|
|
var (
|
|
|
|
_ Identifier = &Image{}
|
|
|
|
_ Drawer = &Image{}
|
|
|
|
_ DrawOrderer = &Image{}
|
|
|
|
_ ParallaxScaler = &Image{}
|
2021-08-20 17:05:47 +10:00
|
|
|
_ Scanner = &Image{}
|
2021-08-18 16:34:51 +10:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2021-08-25 15:04:38 +10:00
|
|
|
gob.Register(&Image{})
|
2021-08-18 16:34:51 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
// Image draws an image at a position.
|
|
|
|
type Image struct {
|
|
|
|
ID
|
2021-08-23 11:10:46 +10:00
|
|
|
Hidden
|
2021-08-18 16:34:51 +10:00
|
|
|
Parallax
|
|
|
|
Pos image.Point
|
2021-08-18 19:27:32 +10:00
|
|
|
Src ImageRef
|
|
|
|
ZOrder
|
2021-08-18 16:34:51 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw draws the image.
|
|
|
|
func (i *Image) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {
|
2021-08-23 11:10:46 +10:00
|
|
|
if i.Hidden {
|
|
|
|
return
|
|
|
|
}
|
2021-08-18 16:34:51 +10:00
|
|
|
var geom ebiten.GeoM
|
|
|
|
geom.Translate(float64(i.Pos.X), float64(i.Pos.Y))
|
|
|
|
geom.Concat(opts.GeoM)
|
|
|
|
opts.GeoM = geom
|
|
|
|
screen.DrawImage(i.Src.Image(), &opts)
|
|
|
|
}
|
2021-08-20 17:05:47 +10:00
|
|
|
|
|
|
|
// Scan returns a slice containing Src.
|
|
|
|
func (i *Image) Scan() []interface{} { return []interface{}{&i.Src} }
|