示例#1
0
文件: main.go 项目: shazow/linerage3d
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)
			}
		}
	})
}
示例#2
0
文件: main.go 项目: acsellers/ofs
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)
			}
		}
	})
}
示例#3
0
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
			}
		}
	})
}
示例#4
0
文件: testapp.go 项目: rockxcn/mobile
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
				}
			}
		}
	})
}
示例#5
0
文件: main.go 项目: arnold8/mobile
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
			}
		}
	})
}
示例#6
0
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)}
			}
		}
	})
}
示例#7
0
func main() {
	app.Main(func(a app.App) {
		var c 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:
				c = e
				touchLocX = float32(c.WidthPt / 1.5)
				touchLocY = float32(c.HeightPt / 1.5)
			case paint.Event:
				onPaint(c)
				a.EndPaint(e)
			case touch.Event:
				touchLocX = e.X / c.PixelsPerPt
				touchLocY = e.Y / c.PixelsPerPt

			}
		}
	})
}
示例#8
0
文件: main.go 项目: paulhankin/mobile
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{})
				}
			}
		}
	})
}
示例#9
0
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)
			}
		}
	})
}
示例#10
0
文件: main.go 项目: rockxcn/mobile
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
			}
		}
	})
}
示例#11
0
文件: game.go 项目: joho/experiments
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
				}
			}
		}
	})
}
示例#12
0
func main() {
	defer func() {
		if err := recover(); err != nil {
			log.Println(err)
		}
	}()
	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{0, 0}
			case paint.Event:
				e.Draw(c)
				a.EndPaint(eve)
			case touch.Event:
				e.touchLoc = geom.Point{geom.Pt(eve.X), geom.Pt(eve.Y)}
			}
		}
	})
}
示例#13
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()
			}
		}
	})
}
示例#14
0
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
				}
			}
		}
	})
}
示例#15
0
文件: main.go 项目: tenntenn/gomoxy
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
			}
		}
	})
}
示例#16
0
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()
				}
			}
		}
	})
}
示例#17
0
文件: main.go 项目: 0x90sled/mobile
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{})
				}
			}
		}
	})
}
示例#18
0
func main() {
	app.Main(func(a app.App) {
		log.Println("Running application...")
		application := &Application{
			goApp: a,
		}
		application.Run()
	})
}
示例#19
0
文件: main.go 项目: dskinner/snd
func main() {
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		go func() {
			time.Sleep(10 * time.Second)
			pprof.StopCPUProfile()
		}()
	}

	app.Main(func(a app.App) {
		var logdbg *time.Ticker
		var glctx gl.Context
		for ev := range a.Events() {
			switch ev := a.Filter(ev).(type) {
			case lifecycle.Event:
				switch ev.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					logdbg = time.NewTicker(time.Second)
					go func() {
						for range logdbg.C {
							log.Printf("fps=%-4v underruns=%-4v buflen=%-4v tickavg=%-12s drift=%s\n",
								fps, al.Underruns(), al.BufLen(), al.TickAverge(), al.DriftApprox())
						}
					}()
					glctx = ev.DrawContext.(gl.Context)
					onStart(glctx)
					al.Start()
				case lifecycle.CrossOff:
					glctx = nil
					logdbg.Stop()
					al.Stop()
					al.CloseDevice()
				}
			case touch.Event:
				env.Touch(ev)
			case size.Event:
				if glctx == nil {
					a.Send(ev)
				} else {
					onLayout(ev)
				}
			case paint.Event:
				if glctx != nil {
					onPaint(glctx)
					a.Publish()
					a.Send(paint.Event{})
				}
			}
		}
	})
}
示例#20
0
文件: spike.go 项目: pyros2097/spike
// It sets up a window and rendering surface and manages the
// different aspects of your application, namely {@link Graphics}, {@link Audio}, {@link Input} and {@link Files}.
// This is the main entry point of your project.
// Note that all Music instances will be automatically paused when the current scene's OnPause() method is
// called, and automatically resumed when the OnResume() method is called.
func Run() {
	lastTime := time.Now()
	app.Main(func(a app.App) {
		var glctx gl.Context
		visible, sz := false, size.Event{}
		for now := range fpsTicker.C {
			if !running {
				break
			}
			deltaTime = now.Sub(lastTime)
			lastTime = now
			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)
						appStart(glctx)
					case lifecycle.CrossOff:
						appStop(glctx)
					}
				case size.Event: // resize event
					sz = e
					touchX = float32(sz.WidthPx / 2)
					touchY = float32(sz.HeightPx / 2)
				case paint.Event:
					if visible {
						appPaint(glctx, sz, float32(deltaTime))
						a.Publish()
						// Keep animating.
						a.Send(paint.Event{})
					}
				case touch.Event:
					// print("Touching")
					// send input events here or before paint just store the last state
					touchX = e.X
					touchY = e.Y
					switch e.Type {
					case touch.TypeBegin:
						// println("Begin")
						doTouchDown(touchX, touchY, 0, 0)
					case touch.TypeEnd:
						// println("End")
						doTouchUp(touchX, touchY, 0, 0)
					case touch.TypeMove:
						// println("Moving")
						doTouchDragged(touchX, touchY, 0)
						// println(e.Sequence)
						// log.Printf("%d", e.Sequence)
					}
				}
			}
		}
	})
}
示例#21
0
func main() {
	t := throfflib.MakeEngine()
	//t = throfflib.LoadGraphics(t)
	t = t.RunString(throfflib.BootStrapString(), "Internal Bootstrap")
	app.Main(func(a app.App) {
		var glctx gl.Context
		var sz size.Event
		for e := range a.Events() {
			//fmt.Printf("")
			//fmt.Printf("PRINTLN [ 1 %v ]",e)
			//if (e) {
			// }

			switch e := a.Filter(e).(type) {
			case lifecycle.Event:
				t.RunString("PRINTLN lifecycle", "HELLO")
				t.RunString(fmt.Sprintf("PRINTLN .S ->STRING [ lifecycle event ] ", e), "HELLO2")
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					glctx, _ = e.DrawContext.(gl.Context)
					onStart(glctx)
					a.Send(paint.Event{})
				case lifecycle.CrossOff:
					onStop(glctx)
					glctx = nil
				}
			case size.Event:
				//t.RunString("PRINTLN size", "HELLO")
				//t.RunString(fmt.Sprintf("PRINTLN .S  ->STRING [ size %v ] ", e), "HELLO2")
				//fmt.Printf("PRINTLN .S ->STRING [ size %v ]", e)
				sz = e
				touchX = float32(sz.WidthPx / 2)
				touchY = float32(sz.HeightPx / 2)
			case paint.Event:
				if glctx == nil || e.External {
					// As we are actively painting as fast as
					// we can (usually 60 FPS), skip any paint
					// events sent by the system.
					continue
				}

				onPaint(glctx, sz)
				a.Publish()
				// Drive the animation by preparing to paint the next frame
				// after this one is shown.
				a.Send(paint.Event{})
			case touch.Event:
				//t.RunString("PRINTLN touch", "HELLO")
				//t.RunString(fmt.Sprintf("PRINTLN  ->STRING [ touch %v ]", e), "HELLO2")
				touchX = e.X
				touchY = e.Y
			}
		}
	})
}
示例#22
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)
				}
			}
		}
	})
}
示例#23
0
func (self *Gomo) Start() {
	peer.LogDebug("IN")
	app.Main(func(a app.App) {
		for e := range a.Events() {

			switch e := a.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:

					// initialize gl peer
					glctx, _ := e.DrawContext.(gl.Context)
					self.glPeer.Initialize(glctx)

					// time to set first scene
					self.onStart <- true
					a.Send(paint.Event{})
				case lifecycle.CrossOff:

					// time to stop application
					self.onStop <- true

					// finalize gl peer
					self.glPeer.Finalize()
				}
			case size.Event:
				peer.SetScreenSize(e)
			case paint.Event:
				if e.External {
					continue
				}

				// update notify for simra
				self.updateCallback()

				// update notify for gl peer
				self.glPeer.Update()

				a.Publish()
				a.Send(paint.Event{})
			case touch.Event:
				switch e.Type {
				case touch.TypeBegin:
					self.touchPeer.OnTouchBegin(e.X, e.Y)
				case touch.TypeMove:
					self.touchPeer.OnTouchMove(e.X, e.Y)
				case touch.TypeEnd:
					self.touchPeer.OnTouchEnd(e.X, e.Y)
				}
			}
		}
	})
	peer.LogDebug("OUT")
}
示例#24
0
文件: main.go 项目: monopole/volley
func main() {
	app.Main(func(a app.App) {
		nsRoot := "/" + net.DetermineNamespaceRoot()
		log.Printf("Using v23.namespace.root=%s", nsRoot)
		engine.NewEngine(
			config.Chatty,
			net.NewV23Manager(
				config.Chatty, config.RootName, false, nsRoot),
		).Run(a)
	})
}
示例#25
0
func main() {
	log.Print("Start main function.")

	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:
				log.Print("event is lifecycle. e = ", e)
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					log.Print("Crosses = CrossOn")
					glctx, _ = e.DrawContext.(gl.Context)
					onStart(glctx)
					a.Send(paint.Event{})
				case lifecycle.CrossOff:
					log.Print("Crosses = CrossOff")
					onStop(glctx)
					glctx = nil
				default:
					log.Print("Crosses = other")

				}
			case size.Event:
				log.Print("event is size. e = ", e)
				sz = e
				touchX = float32(sz.WidthPx / 2)
				touchY = float32(sz.HeightPx / 2)
			case paint.Event:
				log.Print("event is paint. e = ", e)
				if glctx == nil || e.External {
					// As we are actively painting as fast as
					// we can (usually 60 FPS), skip any paint
					// events sent by the system.
					continue
				}

				onPaint(glctx, sz)
				a.Publish()
				a.Send(paint.Event{})
			case touch.Event:
				log.Print("event is touch. e = ", e)
				touchX = e.X
				touchY = e.Y
			default:
				log.Print("unhandled event. e = ", e)
			}
		}
	})

	log.Print("Exit main function.")
}
示例#26
0
func main() {
	rand.Seed(time.Now().UnixNano())

	app.Main(func(a app.App) {
		var glctx gl.Context
		/**
		 sizeについて
		 - 画面に変更があった場合のEvent
		 - アプリ起動時にpaint.Eventが発生する前に1度必ず呼ばれる
		 - サイズ情報が格納されている
		**/
		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:
					// App visible
					glctx, _ = e.DrawContext.(gl.Context)
					onStart(glctx)
					a.Send(paint.Event{})
				case lifecycle.CrossOff:
					// App no longer visible.
					onStop()
					glctx = nil
				}
			case size.Event:
				sz = e
			case paint.Event:
				// OpenGLとOSからの描画イベントは無視する
				if glctx == nil || e.External {
					continue
				}
				// シーングラフを構築し、描画
				onPaint(glctx, sz)
				// 最終的に画面に出力
				a.Publish()
				a.Send(paint.Event{}) // keep animating
			case touch.Event: // タッチイベント
				if down := e.Type == touch.TypeBegin; down || e.Type == touch.TypeEnd {
					game.Press(down)
				}
			case key.Event: // キーボードイベント
				if e.Code != key.CodeSpacebar { // スペースキーのみをイベントとする
					break
				}
				if down := e.Direction == key.DirPress; down || e.Direction == key.DirRelease {
					game.Press(down)
				}
			}
		}
	})
}
示例#27
0
文件: main.go 项目: sunqb/mobile
func main() {
	app.Main(func(a app.App) {
		var c config.Event
		for e := range a.Events() {
			switch e := app.Filter(e).(type) {
			case config.Event:
				c = e
			case paint.Event:
				onPaint(c)
				a.EndPaint()
			}
		}
	})
}
示例#28
0
func main() {
	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)
			case key.Event:
				move(e)
			}
		}
	})
}
示例#29
0
func main() {
	// checkNetwork runs only once when the app first loads.
	app.Main(func(a app.App) {
		str, err := osversion.GetString()
		if err != nil {
			log.Println("Error")
		}
		log.Println(str)

		str, err = osversion.GetHumanReadable()
		if err != nil {
			log.Println("Error")
		}
		log.Println(str)
	})
}
示例#30
0
func main() {
	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)
			case touch.Event:
				duck.MoveToTouch(e, eng)
			}
		}
	})
}