-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprite.go
45 lines (36 loc) · 869 Bytes
/
sprite.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package gophengine
import (
"image"
"github.com/MatusOllah/gophengine/internal/anim"
"github.com/hajimehoshi/ebiten/v2"
)
type Sprite struct {
Position image.Point
Img *ebiten.Image
Visible bool
AnimController *anim.AnimController
}
func NewSprite(x, y int) *Sprite {
return &Sprite{
Position: image.Pt(x, y),
Visible: true,
AnimController: anim.NewAnimController(),
}
}
func (s *Sprite) DrawImageOptions() *ebiten.DrawImageOptions {
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(s.Position.X), float64(s.Position.Y))
return op
}
func (s *Sprite) Draw(img *ebiten.Image) {
if !s.Visible {
return
}
img.DrawImage(s.Img, s.DrawImageOptions())
}
func (s *Sprite) DrawWithOptions(img *ebiten.Image, opts *ebiten.DrawImageOptions) {
if !s.Visible {
return
}
img.DrawImage(s.Img, opts)
}