当前位置: 首页>>代码示例>>Golang>>正文


Golang app.Main函数代码示例

本文整理汇总了Golang中golang.org/x/mobile/app.Main函数的典型用法代码示例。如果您正苦于以下问题:Golang Main函数的具体用法?Golang Main怎么用?Golang Main使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Main函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	log.SetOutput(os.Stdout)

	camera := NewQuatCamera()
	engine := Engine{
		camera:   camera,
		bindings: DefaultBindings(),
		scene:    NewScene(),
	}

	app.Main(func(a app.App) {
		var c config.Event
		for e := range a.Events() {
			switch e := app.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					engine.Start()
				case lifecycle.CrossOff:
					engine.Stop()
				}
			case config.Event:
				engine.Config(e, c)
				c = e
			case paint.Event:
				engine.Draw(c)
				a.EndPaint(e)
			case touch.Event:
				engine.Touch(e, c)
			case key.Event:
				engine.Press(e, c)
			}
		}
	})
}
开发者ID:shazow,项目名称:linerage3d,代码行数:35,代码来源:main.go

示例2: main

func main() {
	flag.Parse()

	v = game.NewVault()
	v.PlaceRoom(9, 0, 1)
	v.PlaceRoom(9, 1, 1)
	v.PlaceRoom(10, 1, 2)

	// setup transparency for sprites
	gl.Disable(gl.DEPTH_TEST)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	app.Main(func(a app.App) {
		var sz size.Event
		for e := range a.Events() {
			switch e := app.Filter(e).(type) {
			case size.Event:
				sz = e
			case paint.Event:
				onPaint(sz)
				a.EndPaint(e)
			}
		}
	})
}
开发者ID:acsellers,项目名称:ofs,代码行数:26,代码来源:main.go

示例3: main

func main() {
	e := Engine{}

	app.Main(func(a app.App) {
		var c size.Event
		for eve := range a.Events() {
			switch eve := app.Filter(eve).(type) {
			case lifecycle.Event:
				switch eve.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					e.Start()
				case lifecycle.CrossOff:
					e.Stop()
				}
			case size.Event:
				c = eve
				e.touchx = float32(c.WidthPt / 2)
				e.touchy = float32(c.HeightPt / 2)
			case paint.Event:
				e.Draw(c)
				a.EndPaint(eve)
			case touch.Event:
				e.touchx = eve.X / c.PixelsPerPt
				e.touchy = eve.Y / c.PixelsPerPt
			}
		}
	})
}
开发者ID:lovexiaov,项目名称:gomobileapp,代码行数:28,代码来源:main.go

示例4: main

func main() {
	app.Main(func(a app.App) {
		addr := "127.0.0.1:" + apptest.Port
		log.Printf("addr: %s", addr)

		conn, err := net.Dial("tcp", addr)
		if err != nil {
			log.Fatal(err)
		}
		defer conn.Close()
		log.Printf("dialled")
		comm := &apptest.Comm{
			Conn:   conn,
			Fatalf: log.Panicf,
			Printf: log.Printf,
		}

		comm.Send("hello_from_testapp")
		comm.Recv("hello_from_host")

		color := "red"
		sendPainting := false
		for e := range a.Events() {
			switch e := app.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					comm.Send("lifecycle_visible")
					sendPainting = true
				case lifecycle.CrossOff:
					comm.Send("lifecycle_not_visible")
				}
			case size.Event:
				comm.Send("size", e.PixelsPerPt, e.Orientation)
			case paint.Event:
				if color == "red" {
					gl.ClearColor(1, 0, 0, 1)
				} else {
					gl.ClearColor(0, 1, 0, 1)
				}
				gl.Clear(gl.COLOR_BUFFER_BIT)
				a.EndPaint(e)
				if sendPainting {
					comm.Send("paint", color)
					sendPainting = false
				}
			case touch.Event:
				comm.Send("touch", e.Type, e.X, e.Y)
				if e.Type == touch.TypeEnd {
					if color == "red" {
						color = "green"
					} else {
						color = "red"
					}
					sendPainting = true
				}
			}
		}
	})
}
开发者ID:rockxcn,项目名称:mobile,代码行数:60,代码来源:testapp.go

示例5: main

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)
					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
				}
				onPaint(glctx, sz)
				a.Publish()
				a.Send(paint.Event{}) // keep animating
			}
		}
	})
}
开发者ID:arnold8,项目名称:mobile,代码行数:29,代码来源:main.go

示例6: main

func main() {
	e := Engine{}

	app.Main(func(a app.App) {
		var c size.Event
		for eve := range a.Events() {
			switch eve := app.Filter(eve).(type) {
			case lifecycle.Event:
				switch eve.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					e.Start()
				case lifecycle.CrossOff:
					e.Stop()
				}
			case size.Event:
				c = eve
				e.touchLoc = geom.Point{c.WidthPt / 2, c.HeightPt / 2}
			case paint.Event:
				e.Draw(c)
				a.EndPaint(eve)
			case touch.Event:
				e.touchLoc = geom.Point{geom.Pt(eve.X), geom.Pt(eve.Y)}
			}
		}
	})
}
开发者ID:lomoalbert,项目名称:gomobileapp,代码行数:26,代码来源:main.go

示例7: main

func main() {
	app.Main(func(a app.App) {
		visible, sz := false, size.Event{}
		for e := range a.Events() {
			switch e := app.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					visible = true
				case lifecycle.CrossOff:
					visible = false
				}
			case size.Event:
				sz = e
			case paint.Event:
				onPaint(sz)
				a.Publish()
				if visible {
					// Keep animating.
					a.Send(paint.Event{})
				}
			}
		}
	})
}
开发者ID:paulhankin,项目名称:mobile,代码行数:25,代码来源:main.go

示例8: main

func main() {
	app.Main(func(a app.App) {
		var glctx gl.Context

		visible := false
		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:
					visible = true
					glctx, _ = e.DrawContext.(gl.Context)
					onStart(glctx, sz)
				case lifecycle.CrossOff:
					visible = false
					onStop(glctx)
				}
			case size.Event:
				sz = e
				touchX = float32(sz.WidthPx / 2)
				touchY = float32(sz.HeightPx / 2)
			case paint.Event:
				onPaint(glctx, sz)
				a.Publish()
				if visible {
					a.Send(paint.Event{})
				}
			case touch.Event:
				onTouch(glctx, e)
			}
		}
	})
}
开发者ID:rakyll,项目名称:GCSolutions,代码行数:35,代码来源:main.go

示例9: main

func main() {
	app.Main(func(a app.App) {
		var sz size.Event
		for e := range a.Events() {
			switch e := app.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					onStart()
				case lifecycle.CrossOff:
					onStop()
				}
			case size.Event:
				sz = e
				touchX = float32(sz.WidthPx / 2)
				touchY = float32(sz.HeightPx / 2)
			case paint.Event:
				onPaint(sz)
				a.EndPaint(e)
			case touch.Event:
				touchX = e.X
				touchY = e.Y
			}
		}
	})
}
开发者ID:rockxcn,项目名称:mobile,代码行数:26,代码来源:main.go

示例10: main

func main() {
	var conf config.Event
	app.Main(func(a app.App) {
		for e := range a.Events() {
			switch ee := app.Filter(e).(type) {
			case paint.Event:
				draw(conf)
				a.EndPaint(e.(paint.Event))
			case touch.Event:
				onTouch(ee, conf)
			case config.Event:
				conf = ee
			case lifecycle.Event:
				switch ee.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					start()
				case lifecycle.CrossOff:
					// occasionally doesn't work and need to CTRL+C the console
					stop()
					return
				}
			}
		}
	})
}
开发者ID:joho,项目名称:experiments,代码行数:25,代码来源:game.go

示例11: main

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()
			}
		}
	})
}
开发者ID:golang-samples,项目名称:gomobile,代码行数:34,代码来源:main.go

示例12: main

func main() {
	app.Main(func(a app.App) {
		var sz size.Event
		for e := range a.Events() {
			switch e := app.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					onStart()
				case lifecycle.CrossOff:
					onStop()
				}
			case size.Event:
				sz = e
				resIndex = float32(sz.WidthPx) / float32(sz.HeightPx)
			case paint.Event:
				onPaint(sz)
				a.EndPaint(e)
			case touch.Event:
				eventType := e.Type.String()
				if eventType == "begin" {
					spin = !spin
				}
			}
		}
	})
}
开发者ID:gitter-badger,项目名称:bukkake,代码行数:27,代码来源:main.go

示例13: main

func main() {
	var proxy *goproxy.ProxyHttpServer
	app.Main(func(a app.App) {
		var sz size.Event
		for e := range a.Events() {
			switch e := app.Filter(e).(type) {
			case lifecycle.Event:
				if e.Crosses(lifecycle.StageAlive) == lifecycle.CrossOn && proxy == nil {
					proxy = goproxy.NewProxyHttpServer()
					//proxy.Verbose = true
					re := regexp.MustCompile(`.*`)
					proxy.OnResponse(goproxy.UrlMatches(re)).DoFunc(
						func(res *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
							if label != nil {
								label.Text = fmt.Sprintf("%s\n%s\n", ctx.Req.URL, label.Text)
								log.Println(ctx.Req.URL)
							}
							return res
						})
					go func() {
						log.Fatal(http.ListenAndServe(":8888", proxy))
					}()
				}
			case paint.Event:
				onPaint(sz)
				a.EndPaint(e)
			case size.Event:
				sz = e
			}
		}
	})
}
开发者ID:tenntenn,项目名称:gomoxy,代码行数:32,代码来源:main.go

示例14: main

func main() {
	// checkNetwork runs only once when the app first loads.
	go checkNetwork()

	app.Main(func(a app.App) {
		var glctx gl.Context
		det, sz := determined, size.Event{}
		for {
			select {
			case <-det:
				a.Send(paint.Event{})
				det = nil

			case e := <-a.Events():
				switch e := a.Filter(e).(type) {
				case lifecycle.Event:
					glctx, _ = e.DrawContext.(gl.Context)
				case size.Event:
					sz = e
				case paint.Event:
					if glctx == nil {
						continue
					}
					onDraw(glctx, sz)
					a.Publish()
				}
			}
		}
	})
}
开发者ID:Christeefym,项目名称:lantern,代码行数:30,代码来源:main.go

示例15: main

func main() {
	app.Main(func(a app.App) {
		var glctx gl.Context
		visible, sz := false, size.Event{}
		for e := range a.Events() {
			switch e := a.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					visible = true
					glctx, _ = e.DrawContext.(gl.Context)
					onStart(glctx)
				case lifecycle.CrossOff:
					visible = false
					onStop()
				}
			case size.Event:
				sz = e
			case paint.Event:
				if visible {
					onPaint(glctx, sz)
					a.Publish()
					// Keep animating.
					a.Send(paint.Event{})
				}
			}
		}
	})
}
开发者ID:0x90sled,项目名称:mobile,代码行数:29,代码来源:main.go


注:本文中的golang.org/x/mobile/app.Main函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。