ichigo/engine/billboard.go

43 lines
762 B
Go
Raw Normal View History

2021-08-26 11:31:39 +10:00
package engine
import (
"encoding/gob"
"image"
"github.com/hajimehoshi/ebiten/v2"
)
2021-08-26 11:33:58 +10:00
// Ensure Billboard satisfies interfaces.
2021-08-27 11:49:11 +10:00
var _ interface {
Identifier
Drawer
Scanner
2021-09-01 09:52:40 +10:00
Transformer
2021-08-27 11:49:11 +10:00
} = &Billboard{}
2021-08-26 11:31:39 +10:00
func init() {
gob.Register(&Billboard{})
}
// Billboard draws an image at a position.
type Billboard struct {
ID
Hidden
Pos image.Point
Src ImageRef
ZOrder
}
// Draw draws the image.
func (b *Billboard) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
screen.DrawImage(b.Src.Image(), opts)
2021-08-26 11:31:39 +10:00
}
// Scan returns a slice containing Src.
func (b *Billboard) Scan() []interface{} { return []interface{}{&b.Src} }
2021-09-03 10:08:56 +10:00
func (b *Billboard) Transform(pt Transform) (tf Transform) {
2021-09-03 09:42:50 +10:00
tf.Opts.GeoM.Translate(cfloat(b.Pos))
2021-09-03 10:08:56 +10:00
return tf.Concat(pt)
}