-
Notifications
You must be signed in to change notification settings - Fork 1
/
animation.go
46 lines (35 loc) · 1009 Bytes
/
animation.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
package main
import (
"github.com/rostislavjadavan/gofb"
)
func main() {
w := gofb.NewWindow("go-fb", 1200, 900, false)
spriteSheet, err := gofb.NewSpriteSheetFromFile("../assets/person_atlas.png", 128, 163)
if err != nil {
panic(err)
}
spriteSheet.Surface().Scale = 2
var frameUpdateTimeMs int64 = 0 // how much time elapsed
var frame = 0 // current animation frame
for w.IsRunning() {
w.StartFrame()
w.Clear(gofb.NewColor3(120, 220, 230))
spriteSheet.Surface().FlipHorizontal = false
spriteSheet.DrawTile(200, 250, frame, 0)
spriteSheet.Surface().FlipHorizontal = true
spriteSheet.DrawTile(600, 250, frame, 1)
frameUpdateTimeMs += w.GetDeltaTimeMs()
// when 100ms elapsed switch to next frame from sprite sheet (and reset timer)
if frameUpdateTimeMs > 100 {
frame++
frameUpdateTimeMs = 0
// there are 8 frames in sprite sheet
if frame > 8 {
frame = 0
}
}
w.FinalizeFrame()
}
defer spriteSheet.Release()
defer w.Destroy()
}