forked from surdeus/gox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprite.go
66 lines (55 loc) · 1.17 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package gg
import (
"github.com/hajimehoshi/ebiten/v2"
//"fmt"
)
type Sprite struct {
Transform
ShaderOptions
Floating bool
Visibility
}
func (s *Sprite) Draw(c *Context) {
// Nothing to draw.
if s.Images[0] == nil {
return
}
t := s.Rectangle().Transform
m := &Matrix{}
tm := t.Matrix()
m.Concat(*tm)
if !s.Floating {
m.Concat(c.Camera.RealMatrix())
}
// Drawing without shader.
if s.Shader == nil {
opts := &ebiten.DrawImageOptions{}
opts.GeoM = *m
c.DrawImage(s.Images[0], opts)
return
}
w, h := s.Images[0].Size()
// Drawing with shader.
opts := &ebiten.DrawRectShaderOptions{
Images: s.Images,
Uniforms: s.Uniforms,
GeoM: *m,
}
c.DrawRectShader(w, h, s.Shader, opts)
}
// Return the rectangle that contains the sprite.
func (s *Sprite) Rectangle() Rectangle {
if s.Images[0] == nil {
panic("trying to get rectangle for nil image pointer")
}
w, h := s.Images[0].Size()
t := s.Transform
t.Around.X *= Float(w)
t.Around.Y *= Float(h)
return Rectangle{t}
}
// Get triangles of the rectangle that contains the sprite
// and has the same widght and height.
func (s *Sprite) Triangles() Triangles {
return s.Rectangle().Triangles()
}