/
scene.go
48 lines (41 loc) · 1.12 KB
/
scene.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
package oak
import (
"time"
"github.com/oakmound/oak/v2/scene"
"github.com/oakmound/oak/v2/timing"
)
var (
// SceneMap is a global map of scenes referred to when scenes advance to
// determine what the next scene should be.
// It can be replaced or modified so long as these modifications happen
// during a scene or before oak has started.
SceneMap = scene.NewMap()
)
func init() {
// The scene "loading" is reserved
err := SceneMap.AddScene("loading", loadingScene)
if err != nil {
panic(err)
}
}
// AddScene is shorthand for oak.SceneMap.AddScene
func AddScene(name string, s scene.Scene) error {
return SceneMap.AddScene(name, s)
}
// Add is shorthand for oak.SceneMap.Add /scene#Add
func Add(name string, start scene.Start, loop scene.Loop, end scene.End) error {
return SceneMap.Add(name, start, loop, end)
}
func sceneTransition(result *scene.Result) {
if result.Transition != nil {
i := 0
tx, _ := screenControl.NewTexture(winBuffer.Bounds().Max)
cont := true
for cont {
cont = result.Transition(winBuffer.RGBA(), i)
drawLoopPublish(tx)
i++
time.Sleep(timing.FPSToDuration(FrameRate))
}
}
}