-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdraw.go
41 lines (35 loc) · 1.2 KB
/
draw.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
package ganim8
import "github.com/hajimehoshi/ebiten/v2"
var drawOpts = DrawOpts(0, 0, 0, 1, 1, 1, 0.5, 0.5)
// DrawSprite draws a sprite to the screen.
func DrawSprite(screen *ebiten.Image, spr *Sprite, index int, x, y, rot, sx, sy, ox, oy float64) {
drawOpts.SetPos(x, y)
drawOpts.SetRot(rot)
drawOpts.SetScale(sx, sy)
drawOpts.SetOrigin(ox, oy)
spr.Draw(screen, index, drawOpts)
}
// DrawSpriteWithOpts draws a sprite to the screen.
func DrawSpriteWithOpts(screen *ebiten.Image, spr *Sprite, index int, opts *DrawOptions, shaderOpts *ShaderOptions) {
if shaderOpts != nil {
spr.DrawWithShader(screen, index, opts, shaderOpts)
} else {
spr.Draw(screen, index, opts)
}
}
// DrawAnime draws an animation to the screen.
func DrawAnime(screen *ebiten.Image, anim *Animation, x, y, rot, sx, sy, ox, oy float64) {
drawOpts.SetPos(x, y)
drawOpts.SetRot(rot)
drawOpts.SetScale(sx, sy)
drawOpts.SetOrigin(ox, oy)
anim.Draw(screen, drawOpts)
}
// DrawAnimeWithOpts draws an anime to the screen.
func DrawAnimeWithOpts(screen *ebiten.Image, anim *Animation, opts *DrawOptions, shaderOpts *ShaderOptions) {
if shaderOpts != nil {
anim.DrawWithShader(screen, opts, shaderOpts)
} else {
anim.Draw(screen, opts)
}
}