ichigo/engine/image.go

39 lines
666 B
Go
Raw Normal View History

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{}
)
func init() {
gob.Register(Image{})
}
// Image draws an image at a position.
type Image struct {
ID
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) {
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)
}