Example #1
0
func main() {
	app.Main(func(a app.App) {
		var glctx gl.Context
		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:
					glctx, _ = e.DrawContext.(gl.Context)
					// transparency of png
					glctx.Enable(gl.BLEND)
					glctx.BlendEquation(gl.FUNC_ADD)
					glctx.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
					onStart(glctx)
					a.Send(paint.Event{})
				case lifecycle.CrossOff:
					onStop()
					glctx = nil
				}
			case size.Event:
				sz = e
			case paint.Event:
				if glctx == nil || e.External {
					continue
				}

				switch sceneId {
				case 0:
					Title.Apply()
				case 1:
					Gopher.Apply()
					Ball.MoveWithReflection()
					Ball.Apply()
				}

				onPaint(glctx, sz)
				a.Publish()
				a.Send(paint.Event{}) // keep animating
			case touch.Event:
				switch sceneId {
				case 1:
					Gopher.Move(e.X, e.Y)
					Gopher.Rotate(Gopher.radian + 5)
					//Gopher.Size(Gopher.width, Gopher.height)
				}
				if e.Type == touch.TypeEnd {
					sceneId = 1
					loadScene(sceneId)
				}
			}
		}
	})
}