本文整理匯總了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)
}
}
示例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)
}
}
示例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)
}
}
示例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
}
示例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)
}
}
}
示例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
}
}
}
}
示例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
}
示例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
}
}
}
}
示例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
}
示例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)
}
示例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
}
示例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
}
}
}
}
示例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
}
示例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)
}
}
示例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
}
}