-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprite.go
50 lines (44 loc) · 934 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
46
47
48
49
50
package main
import "github.com/hajimehoshi/ebiten"
// Sprite structure
type Sprite struct {
x int
y int
rotate float64
scaleX float64
scaleY float64
op ebiten.DrawImageOptions
image *ebiten.Image
}
// NewSprite Alloc a new Sprite in the heap
func NewSprite(image *ebiten.Image) *Sprite {
return &Sprite{
x: 0,
y: 0,
rotate: 0,
scaleX: 1,
scaleY: 1,
op: ebiten.DrawImageOptions{},
image: image,
}
}
// MakeSprite Alloc a new Sprite in the stack
func MakeSprite(image *ebiten.Image) Sprite {
return Sprite{
x: 0,
y: 0,
rotate: 0,
scaleX: 1,
scaleY: 1,
op: ebiten.DrawImageOptions{},
image: image,
}
}
// Draw the sprite on screen
func (s *Sprite) Draw(screen *ebiten.Image) {
s.op.GeoM.Reset()
s.op.GeoM.Scale(s.scaleX, s.scaleY)
s.op.GeoM.Rotate(s.rotate)
s.op.GeoM.Translate(float64(s.x), float64(s.y))
screen.DrawImage(s.image, &s.op)
}