-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.go
46 lines (44 loc) · 937 Bytes
/
main.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 (
"golang.org/x/mobile/app"
"golang.org/x/mobile/event/key"
"golang.org/x/mobile/event/lifecycle"
"golang.org/x/mobile/event/paint"
"golang.org/x/mobile/event/size"
"golang.org/x/mobile/event/touch"
"golang.org/x/mobile/gl"
)
func main() {
app.Main(func(a app.App) {
game := Game{}
var sz size.Event
for e := range a.Events() {
switch e := a.Filter(e).(type) {
case lifecycle.Event:
switch e.Crosses(lifecycle.StageVisible) {
case lifecycle.CrossOn:
glc, _ := e.DrawContext.(gl.Context)
if glc == nil {
continue
}
game.Init(glc)
a.Send(paint.Event{})
case lifecycle.CrossOff:
game.Stop()
}
case size.Event:
sz = e
case paint.Event:
if game.glc == nil || e.External {
continue
}
game.Draw()
a.Publish()
a.Send(paint.Event{})
case touch.Event:
game.Click(sz, e.X, e.Y)
case key.Event:
}
}
})
}