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


Golang sdl.PollEvent函数代码示例

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


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

示例1: Run

func (s *Sim) Run() {
	for s.ui.running {

		start := time.Now()

		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch ev := e.(type) {
			case *sdl.QuitEvent:
				s.ui.running = false
			case *sdl.KeyboardEvent:
				if ev.Keysym.Sym == sdl.K_ESCAPE {
					s.ui.running = false
				} else if ev.Keysym.Sym == sdl.K_SPACE {
					if !s.running {
						s.running = true
						go s.Update()
					}
				}
			}
		}

		s.Draw()

		sdl.GL_SwapBuffers()

		fps := 1 / (float64(time.Since(start)) / float64(time.Second))
		_ = fps
		//fmt.Printf("%f\n", fps)
	}
}
开发者ID:erikmuttersbach,项目名称:PotentialFieldGL,代码行数:30,代码来源:simulator.go

示例2: HandleEvents

func HandleEvents() {
	ch := make(chan func(), 10)

	for Running {
		for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() {
			switch e := ev.(type) {
			case *sdl.QuitEvent:
				Running = false
			case *sdl.MouseButtonEvent:
				if e.State == 1 {
					x, y := int(e.X), int(e.Y)
					switch e.Button {
					case 1:
						queue(ch, func() { ToggleCell(x/Scale, y/Scale) })
					case 2:
						queue(ch, func() { AddAcorn(x/Scale, y/Scale) })
					case 3:
						queue(ch, func() { AddGlider(x/Scale, y/Scale) })
					}
				}
			case *sdl.KeyboardEvent:
				if e.State == 1 {
					switch e.Keysym.Sym {
					case sdl.K_ESCAPE:
						Running = false
					case sdl.K_SPACE, sdl.K_p:
						TogglePause(ch)
					}
				}
			}
		}

		sdl.Delay(25)
	}
}
开发者ID:manveru,项目名称:go.life,代码行数:35,代码来源:life.go

示例3: HandleEvents

func (world *World) HandleEvents() {
	for world.running {
		for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() {
			switch e := ev.(type) {
			case *sdl.QuitEvent:
				world.running = false
			case *sdl.KeyboardEvent:
				switch sdl.GetKeyName(sdl.Key(e.Keysym.Sym)) {
				case "p":
					world.pause = !world.pause
				case "j":
					world.Paddle.Go(0, world.Paddle.vector.Y+world.Paddle.speed)
				case "k":
					world.Paddle.Go(0, world.Paddle.vector.Y-world.Paddle.speed)
				case "q":
					world.running = false
				}
			case *sdl.MouseMotionEvent:
				world.Paddle.Go(float64(e.X), float64(e.Y))
			}
		}

		sdl.Delay(25)
	}
}
开发者ID:manveru,项目名称:go-pong,代码行数:25,代码来源:pong.go

示例4: gameOverScreen

func gameOverScreen(
	screen *sdl.Surface,
	score string,
	bg *glh.Texture,
	font *gltext.Font) bool {

	for {
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch e.(type) {
			case *sdl.ResizeEvent:
				resize(screen, e.(*sdl.ResizeEvent))
			case *sdl.QuitEvent:
				return true
			case *sdl.MouseButtonEvent:
				return false
			}
		}
		renderBackground(screen, bg)
		font.Printf(110, 50, "Game Over")
		font.Printf(110, 100, "Your score: "+score)
		font.Printf(110, 150, "Click to play again")
		sdl.GL_SwapBuffers()
		time.Sleep((1 / 30) * time.Second)
	}
	return false
}
开发者ID:Tohie,项目名称:GoFlappyBird,代码行数:27,代码来源:flappybird.go

示例5: main

func main() {
	if sdl.Init(sdl.INIT_VIDEO) < 0 {
		panic("Video initialization failed: " + sdl.GetError())
	}

	if sdl.EnableKeyRepeat(100, 25) != 0 {
		panic("Setting keyboard repeat failed: " + sdl.GetError())
	}

	videoFlags := sdl.OPENGL    // Enable OpenGL in SDL
	videoFlags |= sdl.DOUBLEBUF // Enable double buffering
	videoFlags |= sdl.HWPALETTE // Store the palette in hardware
	// FIXME: this causes segfault.
	// videoFlags |= sdl.RESIZABLE // Enable window resizing

	surface = sdl.SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, uint32(videoFlags))

	if surface == nil {
		panic("Video mode set failed: " + sdl.GetError())
	}

	sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1)
	initGL()
	resizeWindow(SCREEN_WIDTH, SCREEN_HEIGHT)

	SetupWorld("data/world.txt")

	// wait for events
	running := true
	isActive := true
	for running {
		for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() {
			switch e := ev.(type) {
			case *sdl.ActiveEvent:
				isActive = e.Gain != 0
			case *sdl.ResizeEvent:
				width, height := int(e.W), int(e.H)
				surface = sdl.SetVideoMode(width, height, SCREEN_BPP, uint32(videoFlags))
				if surface == nil {
					fmt.Println("Could not get a surface after resize:", sdl.GetError())
					Quit(1)
				}
				resizeWindow(width, height)
			case *sdl.KeyboardEvent:
				if e.Type == sdl.KEYDOWN {
					handleKeyPress(e.Keysym)
				}
			case *sdl.QuitEvent:
				running = false
			}
		}

		// draw the scene
		if isActive {
			drawGLScene(sector1)
		}
	}
}
开发者ID:navneet1v,项目名称:opengl-go-tutorials,代码行数:58,代码来源:lesson10.go

示例6: wrap

// Wrap the SDL into one single thread
func (s SdlWrap) wrap() {
	runtime.LockOSThread()

	if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
		panic("Unable to init SDL. Cause: " + sdl.GetError())
	}
	sdl.EnableUNICODE(1)

	s.InitDone <- struct{}{}

	for {
		select {
		case t := <-s.Title:
			sdl.WM_SetCaption(t, t)
		case <-s.Quit:
			close(s.Events)
			sdl.Quit()
		case sz := <-s.Size:
			s.Surface <- sdl.SetVideoMode(int(sz.X), int(sz.Y), 32, sdl.HWSURFACE|sdl.DOUBLEBUF|sdl.RESIZABLE)
		default:
			e := sdl.PollEvent()
			if e != nil {
				s.Events <- e
			}
		}
	}
}
开发者ID:andrebq,项目名称:wde.sdl,代码行数:28,代码来源:init.go

示例7: eventLoop

func eventLoop(mouseC chan Point) {
	var p Point
EVENTLOOP:
	switch e := sdl.PollEvent().(type) {
	case *sdl.MouseButtonEvent:
		if e.Type == sdl.MOUSEBUTTONDOWN {
			p.X, p.Y = uint(e.X), uint(e.Y)
			mouseC <- p
		}
	case *sdl.KeyboardEvent:
		if e.State == 0 {
			break
		}

		keysym := e.Keysym.Sym
		if keysym == sdl.K_q {
			os.Exit(0)
		}
	case *sdl.QuitEvent:
		os.Exit(0)
	}

	runtime.Gosched()
	goto EVENTLOOP

}
开发者ID:suapapa,项目名称:whac-a-gopher,代码行数:26,代码来源:event.go

示例8: Update

func (this *Listener) Update() {
	for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
		switch e.(type) {
		case *sdl.QuitEvent:
			this.quit = true
			break
		case *sdl.KeyboardEvent:
			ke := e.(*sdl.KeyboardEvent)
			if ke.Type == sdl.KEYDOWN {
				this.keys[ke.Keysym.Sym] = keyPressed
			} else if ke.Type == sdl.KEYUP {
				this.keys[ke.Keysym.Sym] = keyUp
			}
		}
	}
}
开发者ID:swantescholz,项目名称:coding,代码行数:16,代码来源:listener.go

示例9: manageEvents

func manageEvents(screen *sdl.Surface, movingUp *bool) bool {
	for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
		switch e.(type) {
		case *sdl.ResizeEvent:
			re := e.(*sdl.ResizeEvent)
			resize(screen, re)
			return false

		case *sdl.MouseButtonEvent:
			*movingUp = !*movingUp
			return false
		case *sdl.QuitEvent:
			return true
		}
	}
	return false
}
开发者ID:Tohie,项目名称:GoFlappyBird,代码行数:17,代码来源:flappybird.go

示例10: eventLoop

func (win *window) eventLoop() {
	if win.ec == nil {
		win.ec = make(chan interface{})
	}

eloop:
	for win.events {
		for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() {
			switch e := ev.(type) {
			case *sdl.KeyboardEvent:
				switch e.Type {
				case sdl.KEYUP:
					win.ec <- gui.KeyEvent{int(-e.Keysym.Sym)}
				case sdl.KEYDOWN:
					win.ec <- gui.KeyEvent{int(e.Keysym.Sym)}
				}
			case *sdl.MouseMotionEvent:
				win.ec <- gui.MouseEvent{
					Buttons: int(e.State),
					Loc:     image.Pt(int(e.X), int(e.Y)),
					Nsec:    time.Nanoseconds(),
				}
			case *sdl.MouseButtonEvent:
				win.ec <- gui.MouseEvent{
					Buttons: int(sdl.GetMouseState(nil, nil)),
					Loc:     image.Pt(int(e.X), int(e.Y)),
					Nsec:    time.Nanoseconds(),
				}
			case *sdl.ResizeEvent:
				win.ec <- gui.ConfigEvent{image.Config{
					win.Screen().ColorModel(),
					int(e.W),
					int(e.H),
				}}
			case *sdl.QuitEvent:
				break eloop
			}
		}
	}

	close(win.ec)
}
开发者ID:dmbreaker,项目名称:Go-SDL,代码行数:42,代码来源:gui.go

示例11: main

func main() {
	var done bool

	sdl.Init(sdl.INIT_VIDEO)

	var screen = sdl.SetVideoMode(300, 300, 18, sdl.OPENGL|sdl.RESIZABLE)

	if screen == nil {
		sdl.Quit()
		panic("Couldn't set 300x300 GL video mode: " + sdl.GetError() + "\n")
	}
	gl.Init()
	//if gl.Init() != nil {
	//panic("gl error")
	//}
	init_()
	reshape(int32(screen.W), int32(screen.H))
	done = false
	for !done {
		for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
			switch e.(type) {
			case *sdl.ResizeEvent:
				re := e.(*sdl.ResizeEvent)
				screen = sdl.SetVideoMode(int(re.W), int(re.H), 16,
					sdl.OPENGL|sdl.RESIZABLE)
				if screen != nil {
					reshape(int32(screen.W), int32(screen.H))
				} else {
					panic("we couldn't set the new video mode??")
				}
				break
			case *sdl.QuitEvent:
				done = true
				break
			}
		}
		done = key_handler()
		draw()
	}
	sdl.Quit()
	return
}
开发者ID:pietdaniel,项目名称:gl_maze,代码行数:42,代码来源:main.go

示例12: loop

func loop(screen *sdl.Surface) {
	for {
		screen.Flip()
		event := sdl.PollEvent()
		if event != nil {
			if _, ok := event.(*sdl.QuitEvent); ok {
				log.Println("Caught quit event. Quiting SDL.")
				break
			}
		}
	}
}
开发者ID:jqln-0,项目名称:colorshow,代码行数:12,代码来源:window.go

示例13: eventLoop

func eventLoop(c *Screen) {
EVENTLOOP:
	/* log.Printf("%#v\n", event) */
	switch e := sdl.PollEvent().(type) {
	case *sdl.QuitEvent:
		os.Exit(0)

	case *sdl.ResizeEvent:
		if opt.fullscreen {
			break
		}
		if err := c.setSurface(int(e.W), int(e.H)); err != nil {
			log.Fatal(err)
		}
		c.updateC <- 1

	case *sdl.KeyboardEvent:
		// Ignore key-up
		if e.State == 0 {
			break
		}

		keysym := e.Keysym.Sym
		if keysym == sdl.K_q {
			quitC <- true
			break
		}

		// tune timestamp
		if v, ok := kmVias[keysym]; ok {
			tsViasC <- v
			break
		}
		// tune font size
		if v, ok := kmFontSize[keysym]; ok {
			c.changeFontSize(v)
			break
		}

		// pause/resume
		if v, ok := kmNavScript[keysym]; ok {
			navC <- v
			break
		}
		log.Printf("Sim:%08x, Mod:%04x, Unicode:%02x, %t\n",
			e.Keysym.Sym, e.Keysym.Mod, e.Keysym.Unicode,
			e.Keysym.Unicode)
	} // end of switch

	runtime.Gosched()
	goto EVENTLOOP
}
开发者ID:suapapa,项目名称:subtitle-raider,代码行数:52,代码来源:event.go

示例14: main

func main() {
	if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
		panic(sdl.GetError())
	}

	if ttf.Init() != 0 {
		panic(sdl.GetError())
	}

	var screen = sdl.SetVideoMode(1400, 300, 32, 0)
	var video_info = sdl.GetVideoInfo()
	println("HW_available = ", video_info.HW_available)
	println("WM_available = ", video_info.WM_available)
	println("Video_mem = ", video_info.Video_mem, "kb")
	sdl.EnableUNICODE(1)

	font := ttf.OpenFont("euler.otf", 24)

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

	black := sdl.Color{0, 0, 0, 0}
	text := ttf.RenderUTF8_Blended(font, "!!", black)
	fmt.Println(text.Bounds())
	sdl.WM_SetCaption("Go-SDL SDL Test", "")
	running := true
	num := NewNumberShower("b+c", "", "euler.otf", 24, 0)
	denom := NewNumberShower("a", "", "euler.otf", 24, 0)
	testy := NewFractionShower(num, denom, "euler.otf", 24, 0)
	testy.CursorPosition = 3
	testy.RenderEmptyIndextxt = true
	str := ""
	for running {
		switch e := sdl.PollEvent().(type) {
		case *sdl.QuitEvent:
			running = false
			break
		case *sdl.KeyboardEvent:

			if e.State == 1 {
				str = handlekeypress2(e.Keysym, str)
				fmt.Println("rendering string", str)
				text = ttf.RenderUTF8_Blended(font, str, black)
			}
		}
		screen.FillRect(nil, 0xFFFFFF)
		screen.Blit(&sdl.Rect{23, 0, 0, 0}, testy.Render(), nil)
		screen.Flip()
		sdl.Delay(5)
	}
}
开发者ID:Englebabz,项目名称:CasGO,代码行数:52,代码来源:main.go

示例15: handleInput

func handleInput() {
	for e := sdl.PollEvent(); e != nil; {
		// just ignore for the moment
	}
	if globalState.speed < 1 {
		globalState.speed = 1
	}
	if speed < 0.5 {
		speed = 0.5
	} else if speed > 2 {
		speed = 2
	}
}
开发者ID:andrebq,项目名称:wfobj,代码行数:13,代码来源:main.go


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