-
Notifications
You must be signed in to change notification settings - Fork 1
/
anim_test.go
43 lines (34 loc) · 922 Bytes
/
anim_test.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
package anim_test
import (
"bytes"
"image"
_ "image/png"
"testing"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/examples/resources/images"
"github.com/setanarut/anim"
)
var im *ebiten.Image
func TestAnim(t *testing.T) {
t.Run("Load Image", LoadImage)
t.Run("Ping Pong", PingPong)
}
func LoadImage(t *testing.T) {
img, _, err := image.Decode(bytes.NewReader(images.Runner_png))
if err != nil {
t.Skip("image load error")
}
im = ebiten.NewImageFromImage(img)
}
func PingPong(t *testing.T) {
img := ebiten.NewImageFromImage(im)
spriteSheet := ebiten.NewImageFromImage(img)
animPlayer := anim.NewAnimationPlayer(spriteSheet)
animPlayer.NewAnimationState("idle", 0, 0, 32, 32, 5, true, false)
frames := animPlayer.Animations["idle"].Frames
secondFrame := frames[1]
lastFrame := frames[len(frames)-1]
if secondFrame != lastFrame {
t.Fatalf("Ping Pong index error")
}
}