-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture.go
More file actions
39 lines (32 loc) · 847 Bytes
/
texture.go
File metadata and controls
39 lines (32 loc) · 847 Bytes
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
package engine
import (
"engine/vec2"
"github.com/hajimehoshi/ebiten/v2"
)
type Texture struct {
BaseNode
Image *ebiten.Image
Offset vec2.T
Scale vec2.T
Rotation float64
GlobalTransform *Transform
}
func NewTexture(name string, image *ebiten.Image, globalTransform *Transform) *Texture {
return &Texture{
BaseNode: *NewNode(name),
Image: image,
Offset: vec2.T{X: 0, Y: 0},
Scale: vec2.T{X: 1, Y: 1},
Rotation: 0,
GlobalTransform: globalTransform,
}
}
func (t *Texture) Draw(screen *ebiten.Image) {
op := &ebiten.DrawImageOptions{}
// Local translation
op.GeoM.Scale(t.Scale.X, t.Scale.Y)
op.GeoM.Rotate(t.Rotation)
op.GeoM.Translate(t.Offset.X, t.Offset.Y)
op.GeoM.Concat(t.GlobalTransform.Matrix())
screen.DrawImage(t.Image, op)
}