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


Golang sdl.PollEvent函数代码示例

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


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

示例1: handleEvents

func (c *Controller) handleEvents() {
	// read all events
	for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
		switch et := event.(type) {
		case *sdl.QuitEvent:
			log.Println("Want to quit, but how do we apply this... ?")
			/*
				c.Destroy()
				return
				// NOTE: caller keeps calling Iterate because it doesn't know we're done... how to fix?
			*/
		case *sdl.KeyDownEvent:
			c.sendKeyEvents(sdl.GetKeyName(et.Keysym.Sym), true)
		case *sdl.KeyUpEvent:
			c.sendKeyEvents(sdl.GetKeyName(et.Keysym.Sym), false)
		// these are events we know but currently don't use FIXME implement
		case *sdl.WindowEvent:
		case *sdl.TextInputEvent:
		case *sdl.TextEditingEvent:
		case *sdl.MouseButtonEvent:
		case *sdl.MouseMotionEvent:
		case *sdl.MouseWheelEvent:
		default:
			log.Printf("Unknown event: %T\n", et)
		}
	}
}
开发者ID:xamino,项目名称:orbengine,代码行数:27,代码来源:controller.go

示例2: CheckForUpdates

// CheckForUpdates polls sdl events and updates the map accordingly
func CheckForUpdates() bool {
	changeDetected := false

	// poll any current events
	var event sdl.Event
	for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
		switch t := event.(type) {
		case *sdl.QuitEvent:
			inputMap["Quit"] = true
		case *sdl.KeyDownEvent:
			if t.Keysym.Sym == sdl.K_ESCAPE {
				inputMap["Esc"] = true
			} else {
				// fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
				// t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
			}
		default:
			// fmt.Printf("Some event\n")
		}

		changeDetected = true
	}

	return changeDetected
}
开发者ID:Triangle345,项目名称:GT,代码行数:26,代码来源:GlobalInput.go

示例3: main

func main() {

	start()
	defer window.Destroy()
	defer renderer.Destroy()

	text := loadText("Press enter to reset", sdl.Color{0, 0, 0, 255})
	startTime := sdl.GetTicks()

	quit := false
	for !quit {
		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch t := e.(type) {
			case *sdl.QuitEvent:
				quit = true
			case *sdl.KeyDownEvent:
				if t.Keysym.Sym == sdl.K_RETURN {
					startTime = sdl.GetTicks()
				}

			}
		}

		renderer.SetDrawColor(0xFF, 0xFF, 0xFF, 0xFF)
		renderer.Clear()
		timeText := loadText(fmt.Sprintf("time: %d", sdl.GetTicks()-startTime), sdl.Color{0, 0, 0, 255})
		renderer.Copy(text, nil, &sdl.Rect{0, 0, 400, 100})
		renderer.Copy(timeText, nil, &sdl.Rect{400, 0, 400, 100})

		renderer.Present()
	}
}
开发者ID:EvanTheB,项目名称:SDLGame,代码行数:32,代码来源:22timer.go

示例4: main

func main() {
	rom, err := LoadROM(os.Args[1])

	if err != nil {
		panic(err)
	}

	frameDelay := 1000 / frameRate

	window := sdl.CreateWindow(
		"Go NES",
		sdl.WINDOWPOS_UNDEFINED,
		sdl.WINDOWPOS_UNDEFINED,
		256,
		240,
		sdl.WINDOW_SHOWN,
	)

	if window == nil {
		panic(sdl.GetError())
	}

	defer window.Destroy()

	controller := NewController()
	ppu := NewPPU(window, NewVRAM(rom.Mapper()))
	cpu := NewCPU(NewMMU(rom.Mapper(), ppu, controller), ppu)

	ticksPerFrame := uint32(341 * 262)

	for {
		expectedTicks := sdl.GetTicks() + frameDelay

		for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
			switch event := event.(type) {
			case *sdl.KeyDownEvent:
				controller.SetKeyState(event.Keysym.Sym, true)
			case *sdl.KeyUpEvent:
				controller.SetKeyState(event.Keysym.Sym, false)
			case *sdl.QuitEvent:
				return
			}
		}

		ppuTicks := uint32(0)

		for ppuTicks < ticksPerFrame {
			ppuTicks += ppu.Tick(cpu.Tick())
		}

		actualTicks := sdl.GetTicks()

		if actualTicks < expectedTicks {
			sdl.Delay(expectedTicks - actualTicks)
		}
	}
}
开发者ID:jlippitt,项目名称:gones,代码行数:57,代码来源:main.go

示例5: main

func main() {
	var window *sdl.Window
	var renderer *sdl.Renderer
	var event sdl.Event
	var running bool

	window = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
		winWidth, winHeight, sdl.WINDOW_SHOWN)
	if window == nil {
		fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", sdl.GetError())
		os.Exit(1)
	}

	renderer = sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
	if renderer == nil {
		fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", sdl.GetError())
		os.Exit(2)
	}

	var peepArray []sdl.Event = make([]sdl.Event, 5)

	running = true
	for running {
		sdl.PumpEvents()
		numEventsRetrieved := sdl.PeepEvents(peepArray, sdl.PEEKEVENT, sdl.FIRSTEVENT, sdl.LASTEVENT)
		if numEventsRetrieved < 0 {
			fmt.Printf("PeepEvents error: %s\n", sdl.GetError())
		} else {
			for i := 0; i < numEventsRetrieved; i++ {
				fmt.Printf("Event Peeked Value: %v\n", peepArray[i]) // primitive printing of event
			}
		}

		for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
			switch t := event.(type) {
			case *sdl.QuitEvent:
				running = false
			case *sdl.MouseMotionEvent:
				fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
					t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
			case *sdl.MouseButtonEvent:
				fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
					t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
			case *sdl.MouseWheelEvent:
				fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
					t.Timestamp, t.Type, t.Which, t.X, t.Y)
			case *sdl.KeyUpEvent:
				fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
					t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
			}
		}
		sdl.Delay(1000 / 30)
	}

	renderer.Destroy()
	window.Destroy()
}
开发者ID:emlai,项目名称:go-sdl2,代码行数:57,代码来源:PeepEvents_peek.go

示例6: main

func main() {

	start()
	defer window.Destroy()
	defer renderer.Destroy()
	loadAudio()

	screens := loadScreens()

	quit := false

	cur := screens["main"]

	for !quit {
		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch t := e.(type) {
			case *sdl.QuitEvent:
				quit = true
			case *sdl.KeyDownEvent:
				switch t.Keysym.Sym {
				case sdl.K_1:
					high.PlayChannel(-1, 0)
				case sdl.K_2:
					medium.PlayChannel(-1, 0)
				case sdl.K_3:
					low.PlayChannel(-1, 0)
				case sdl.K_4:
					scratch.PlayChannel(-1, 0)
				case sdl.K_9:
					if !mix.MusicPlaying() {
						if !music.Play(1) {
							fmt.Printf("music did not play: %s", sdl.GetError())
						}
					} else {
						if !mix.PausedMusic() {
							mix.PauseMusic()
						} else {
							mix.ResumeMusic()
						}

					}
				}

			}

		}

		renderer.SetDrawColor(0xFF, 0xFF, 0xFF, 0xFF)
		renderer.Clear()

		renderer.Copy(cur, nil, nil)

		renderer.Present()
	}
}
开发者ID:EvanTheB,项目名称:SDLGame,代码行数:55,代码来源:21sound.go

示例7: catchEvents

func catchEvents() bool {
	for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
		switch t := event.(type) {
		case *sdl.QuitEvent:
			return false
		case *sdl.KeyDownEvent:
			handleKeyEvent(t.Keysym.Sym)
		}
	}
	return true
}
开发者ID:billyninja,项目名称:wander,代码行数:11,代码来源:main.go

示例8: eventLoop

func (g *Engine) eventLoop() {
	g.Event = nil
	for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
		switch t := event.(type) {
		case *sdl.QuitEvent:
			g.Running = false

		case *sdl.KeyDownEvent:
			g.Event = &t.Keysym.Sym
		}
	}
}
开发者ID:stephenbinns,项目名称:ein,代码行数:12,代码来源:engine.go

示例9: waitEvent

//wait for an event and returns the value of the event in key_mapping
func (c *Chip8) waitEvent() byte {

	for {
		for c.event = sdl.PollEvent(); c.event != nil; c.event = sdl.PollEvent() {
			switch event := c.event.(type) {
			case *sdl.KeyDownEvent:
				if code, found := c.key_mapping[event.Keysym.Sym]; found {
					return code
				}
			}
		}
	}
}
开发者ID:PeBraz,项目名称:Chip.emul8ter,代码行数:14,代码来源:chip8.go

示例10: main

func main() {
	var winTitle string = "Go-SDL2 + Go-GL"
	var winWidth, winHeight int = 800, 600
	var window *sdl.Window
	var context sdl.GLContext
	var event sdl.Event
	var running bool
	var err error

	if err = sdl.Init(sdl.INIT_EVERYTHING); err != nil {
		panic(err)
	}
	defer sdl.Quit()

	if err = gl.Init(); err != nil {
		panic(err)
	}

	window, err = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
		winWidth, winHeight, sdl.WINDOW_OPENGL)
	if err != nil {
		panic(err)
	}
	defer window.Destroy()
	context, err = sdl.GL_CreateContext(window)
	if err != nil {
		panic(err)
	}
	defer sdl.GL_DeleteContext(context)

	gl.Enable(gl.DEPTH_TEST)
	gl.ClearColor(0.2, 0.2, 0.3, 1.0)
	gl.ClearDepth(1)
	gl.DepthFunc(gl.LEQUAL)
	gl.Viewport(0, 0, int32(winWidth), int32(winHeight))

	running = true
	for running {
		for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
			switch t := event.(type) {
			case *sdl.QuitEvent:
				running = false
			case *sdl.MouseMotionEvent:
				fmt.Printf("[%d ms] MouseMotion\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n", t.Timestamp, t.Which, t.X, t.Y, t.XRel, t.YRel)
			}
		}
		drawgl()
		sdl.GL_SwapWindow(window)
	}
}
开发者ID:emlai,项目名称:go-sdl2,代码行数:50,代码来源:opengl.go

示例11: main

func main() {
	window, renderer = tools.Start("planets", int(SCREEN_W), int(SCREEN_H))
	wideView := tools.ViewBox{tools.Vector{-SCREEN_SCALE / 2 / float64(SCREEN_H) * float64(SCREEN_W),
		-SCREEN_SCALE / 2},
		SCREEN_SCALE / float64(SCREEN_H) * float64(SCREEN_W),
		SCREEN_SCALE}
	defer window.Destroy()
	defer renderer.Destroy()
	sprite = tools.LoadTextureTransparent(renderer, "resources/sprites.png", 0, 0xFF, 0xFF)

	bodies := []*tools.Body{&Sun, &Earth, &Mars, &Ecc}

	quit := false
	curView := &wideView
	for !quit {
		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch t := e.(type) {
			case *sdl.QuitEvent:
				quit = true
			case *sdl.KeyDownEvent:
				switch t.Keysym.Sym {
				case sdl.K_UP:
					auto := tools.GetAutoView(
						[]tools.Vector{
							bodies[0].Position,
							bodies[1].Position},
						SCREEN_RATIO)
					curView = &auto
				case sdl.K_DOWN:
					curView = &wideView
				case sdl.K_q:
					quit = true
				}
				// fmt.Println("View:", curView)
			}

		}
		// Draw background
		renderer.SetDrawColor(0xFF, 0xFF, 0xFF, 0xFF)
		renderer.Clear()

		renderer.SetDrawColor(0, 0, 0, 0xFF)

		tools.UpdateBodiesSeconds(bodies, 60*60*24*7)
		DrawBodies(bodies, *curView)

		renderer.Present()
		//fmt.Println(earth.Position, sun.Position)
	}
}
开发者ID:EvanTheB,项目名称:SDLGame,代码行数:50,代码来源:game.go

示例12: HandleEvents

func (i *InputHandler) HandleEvents() {
	i.pressed_keys_this_frame = make([]sdl.Keycode, 10)
	i.released_keys_this_frame = make([]sdl.Keycode, 10)

	for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
		switch t := event.(type) {
		case *sdl.KeyDownEvent:
			i.pressed_keys_this_frame = append(i.pressed_keys_this_frame, t.Keysym.Sym)
			i.pressed_keys[t.Keysym.Sym] = true
		case *sdl.KeyUpEvent:
			i.released_keys_this_frame = append(i.released_keys_this_frame, t.Keysym.Sym)
			i.pressed_keys[t.Keysym.Sym] = false
		}
	}
}
开发者ID:kageurufu,项目名称:platformr,代码行数:15,代码来源:input.go

示例13: main

func main() {
	window, err := sdl.CreateWindow("Monster Path",
		sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
		640, 480, sdl.WINDOW_SHOWN)

	if err != nil {
		os.Exit(1)
	}
	defer window.Destroy()

	renderer, err := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
	if err != nil {
		os.Exit(2)
	}
	defer renderer.Destroy()

	var event sdl.Event
	running := true

	myGrid := grid.New(17, 12)
	setupMap(myGrid)
	gunner.location, _ = myGrid.RoomAt(15, 7)
	alien.location, _ = myGrid.RoomAt(1, 1)
	graph := graph.NewFromGrid(myGrid)
	path := graph.Path(gunner.location, alien.location)
	for running {
		for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
			switch event.(type) {
			case *sdl.QuitEvent:
				running = false
			}
		}

		renderer.SetDrawColor(205, 201, 201, 255)
		renderer.Clear()

		renderer.SetDrawColor(10, 10, 10, 255)
		Draw(renderer, myGrid)
		DrawGraph(renderer, graph)
		renderer.SetDrawColor(200, 0, 0, 255)
		DrawPath(renderer, path)

		renderer.SetDrawColor(0, 100, 0, 255)
		alien.Draw(renderer)
		gunner.Draw(renderer)
		renderer.Present()
	}
}
开发者ID:paytonrules,项目名称:pathfinding,代码行数:48,代码来源:gameloop.go

示例14: processInput

func (p *PlayerFrontend) processInput() {
	for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() {
		input := Input{}
		for _, v := range p.inputs {
			earlyExit, in := v.ProcessEvent(ev, p)
			if in != nil {
				input.Combine(in)
			}
			if earlyExit {
				break
			}
		}
		input.Normalize()
		p.sendInput(input)
	}
}
开发者ID:Oralordos,项目名称:Game-Programming-Project,代码行数:16,代码来源:frontend.go

示例15: Poll

func Poll() Event {
	e := sdl.PollEvent()
	if e == nil {
		return nil
	}
	return wrapEvent(e)
}
开发者ID:eandre,项目名称:drip,代码行数:7,代码来源:poll.go


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