本文整理汇总了Golang中github.com/banthar/Go-SDL/sdl.PollEvent函数的典型用法代码示例。如果您正苦于以下问题:Golang PollEvent函数的具体用法?Golang PollEvent怎么用?Golang PollEvent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PollEvent函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: ui_main
func ui_main() {
if sdl.Init(sdl.INIT_VIDEO) != 0 {
panic(sdl.GetError())
}
if screen == nil {
panic(sdl.GetError())
}
sdl.EnableUNICODE(1)
sdl.WM_SetCaption("Go-SDL SDL Test", "")
running := true
for running {
for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() {
switch e := ev.(type) {
case *sdl.QuitEvent:
running = false
break
case *sdl.ResizeEvent:
println("resize screen ", e.W, e.H)
screen = sdl.SetVideoMode(int(e.W), int(e.H), 32, sdl.RESIZABLE)
if screen == nil {
panic(sdl.GetError())
}
}
}
}
ttf.Quit()
sdl.Quit()
}
开发者ID:AlexandreBRUXELLE,项目名称:goStartDockerViaRabbitMQ,代码行数:39,代码来源:main.go
示例17: mainLoop
func mainLoop() {
done := false
for !done {
for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
switch e.(type) {
case *sdl.QuitEvent:
done = true
break
case *sdl.KeyboardEvent:
keyEvent := e.(*sdl.KeyboardEvent)
if keyEvent.Type == sdl.KEYDOWN {
done = handleKey(keyEvent)
}
}
}
updateShaderParams()
draw()
drawOverlay()
sdl.GL_SwapBuffers()
checkShaders()
}
}
开发者ID:shogg,项目名称:glvox,代码行数:23,代码来源:main.go
示例18: main
// Runs the games main loop.
func (g *game) main() (err error) {
g.running = true
for g.running {
for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
switch ev := e.(type) {
case *sdl.KeyboardEvent:
err = g.onKeyboardEvent(ev)
if err != nil {
return
}
case *sdl.MouseMotionEvent:
err = g.onMouseMotionEvent(ev)
if err != nil {
return
}
case *sdl.MouseButtonEvent:
err = g.onMouseButtonEvent(ev)
if err != nil {
return
}
case *sdl.QuitEvent:
g.running = false
}
}
g.screen.FillRect(nil, 0)
err = g.draw()
if err != nil {
return
}
g.screen.Flip()
}
return
}
开发者ID:DeedleFake,项目名称:ggigl,代码行数:37,代码来源:ggigl.go
示例19: mainLoop
func mainLoop() {
done := false
for !done {
for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
switch e.(type) {
case *sdl.QuitEvent:
done = true
break
case *sdl.KeyboardEvent:
key := e.(*sdl.KeyboardEvent).Keysym.Sym
if key == sdl.K_RETURN {
done = true
break
} else {
handleKey(key)
}
}
}
draw()
drawOverlay()
sdl.GL_SwapBuffers()
}
}
开发者ID:shogg,项目名称:gltoy,代码行数:24,代码来源:gltoy.go
示例20: main
func main() {
if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
panic(sdl.GetError())
}
// The actual resolution (screenspace)
W := 800
H := 600
// The virtual resolution (worldspace)
MAXX := 400
MAXY := 300
screen := sdl.SetVideoMode(W, H, 32, sdl.FULLSCREEN)
if screen == nil {
panic(sdl.GetError())
}
sdl.EnableUNICODE(1)
sdl.ShowCursor(0)
sdl.WM_SetCaption("Random Lines", "")
red := sdl.Color{255, 0, 0, 255}
color := red
rand.Seed(time.Now().UnixNano())
for {
color = sdl.Color{uint8(rand.Intn(255)), uint8(rand.Intn(255)), uint8(rand.Intn(255)), 255}
DoublePixelLine(screen, rand.Intn(MAXX), rand.Intn(MAXY), rand.Intn(MAXX), rand.Intn(MAXY), color)
if escPressed() {
break
}
screen.Flip()
sdl.PollEvent()
//sdl.Delay(10)
}
sdl.Quit()
}
开发者ID:xyproto,项目名称:rasterizer,代码行数:40,代码来源:rasterizer.go
注:本文中的github.com/banthar/Go-SDL/sdl.PollEvent函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论