Example #1
0
// Run starts the mobile application.
//
// It must be called directly from the main function and will block until the
// application exits.
//
// Deprecated: call Main directly instead.
func Run(cb Callbacks) {
	Main(func(a App) {
		var c event.Config
		for e := range a.Events() {
			switch e := event.Filter(e).(type) {
			case event.Lifecycle:
				switch e.Crosses(event.LifecycleStageVisible) {
				case event.ChangeOn:
					if cb.Start != nil {
						cb.Start()
					}
				case event.ChangeOff:
					if cb.Stop != nil {
						cb.Stop()
					}
				}
			case event.Config:
				if cb.Config != nil {
					cb.Config(e, c)
				}
				c = e
			case event.Draw:
				if cb.Draw != nil {
					cb.Draw(c)
				}
				a.EndDraw()
			case event.Touch:
				if cb.Touch != nil {
					cb.Touch(e, c)
				}
			}
		}
	})
}
Example #2
0
func main() {
	app.Main(func(a app.App) {
		var c event.Config
		var eng *WritableEngine
		var root *sprite.Node
		startClock := time.Now()
		for e := range a.Events() {
			switch e := event.Filter(e).(type) {
			case event.Config:
				c = e
			case event.Draw:
				if eng == nil || root == nil {
					eng = NewWritableEngine(
						glsprite.Engine(),
						image.Rect(0, 0, int(c.Width.Px(c.PixelsPerPt)), int(c.Height.Px(c.PixelsPerPt))),
						color.White,
					)
					root = loadScene(eng, loadTextures(eng))
					go listen(eng, ":8080")
				}
				now := clock.Time(time.Since(startClock) * 60 / time.Second)
				gl.ClearColor(1, 1, 1, 1)
				gl.Clear(gl.COLOR_BUFFER_BIT)
				gl.Enable(gl.BLEND)
				gl.BlendEquation(gl.FUNC_ADD)
				gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
				if eng != nil && root != nil {
					eng.Render(root, now, c)
				}
				a.EndDraw()
			}
		}
	})
}
Example #3
0
// Run starts the mobile application.
//
// It must be called directly from the main function and will block until the
// application exits.
//
// Deprecated: call Main directly instead.
func Run(cb Callbacks) {
	Main(func(a App) {
		var c config.Event
		for e := range a.Events() {
			switch e := event.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					if cb.Start != nil {
						cb.Start()
					}
				case lifecycle.CrossOff:
					if cb.Stop != nil {
						cb.Stop()
					}
				}
			case config.Event:
				if cb.Config != nil {
					cb.Config(e, c)
				}
				c = e
			case paint.Event:
				if cb.Draw != nil {
					cb.Draw(c)
				}
				a.EndDraw()
			case touch.Event:
				if cb.Touch != nil {
					cb.Touch(e, c)
				}
			}
		}
	})
}
Example #4
0
func main() {
	// checkNetwork runs only once when the app first loads.
	go checkNetwork()

	app.Main(func(a app.App) {
		var c config.Event
		for e := range a.Events() {
			switch e := event.Filter(e).(type) {
			case config.Event:
				c = e
			case paint.Event:
				onDraw(c)
				a.EndPaint()
			}
		}
	})
}
Example #5
0
func main() {
	app.Main(func(a app.App) {
		var c event.Config
		for e := range a.Events() {
			switch e := event.Filter(e).(type) {
			case event.Lifecycle:
				switch e.Crosses(event.LifecycleStageVisible) {
				case event.ChangeOn:
					start()
				case event.ChangeOff:
					stop()
				}
			case event.Config:
				//config(e, c)
				c = e
			case event.Draw:
				draw(c)
				a.EndDraw()
			case event.Touch:
				touch(e, c)
			}
		}
	})
}
Example #6
0
func main() {
	app.Main(func(a app.App) {
		var c config.Event
		for e := range a.Events() {
			switch e := event.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					onStart()
				case lifecycle.CrossOff:
					onStop()
				}
			case config.Event:
				c = e
				touchLoc = geom.Point{c.Width / 2, c.Height / 2}
			case paint.Event:
				onDraw(c)
				a.EndDraw()
			case touch.Event:
				touchLoc = e.Loc
			}
		}
	})
}