本文整理匯總了Golang中github.com/veandco/go-sdl2/sdl.Window.GetID方法的典型用法代碼示例。如果您正苦於以下問題:Golang Window.GetID方法的具體用法?Golang Window.GetID怎麽用?Golang Window.GetID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/veandco/go-sdl2/sdl.Window
的用法示例。
在下文中一共展示了Window.GetID方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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, 2)
peepArray[0] = &sdl.UserEvent{sdl.USEREVENT, sdl.GetTicks(), window.GetID(), 1331, nil, nil}
peepArray[1] = &sdl.UserEvent{sdl.USEREVENT, sdl.GetTicks(), window.GetID(), 10101, nil, nil}
running = true
lastPushTime := sdl.GetTicks()
for running {
if lastPushTime+pushTime < sdl.GetTicks() {
lastPushTime = sdl.GetTicks()
sdl.PumpEvents()
numEventsHandled := sdl.PeepEvents(peepArray, sdl.ADDEVENT, sdl.FIRSTEVENT, sdl.LASTEVENT)
if numEventsHandled < 0 {
fmt.Printf("PeepEvents error: %s\n", sdl.GetError())
} else {
fmt.Printf("Successful push of %d events\n", numEventsHandled)
}
}
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)
case *sdl.UserEvent:
fmt.Printf("[%d ms] UserEvent\tcode:%d\n", t.Timestamp, t.Code)
}
}
sdl.Delay(1000 / 30)
}
renderer.Destroy()
window.Destroy()
}
示例2: 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)
}
running = true
lastPushTime := sdl.GetTicks()
for running {
// Push a UserEvent every second
if lastPushTime+pushTime < sdl.GetTicks() {
lastPushTime = sdl.GetTicks()
pEvent := &sdl.UserEvent{sdl.USEREVENT, sdl.GetTicks(), window.GetID(), 1331, nil, nil}
retVal := sdl.PushEvent(pEvent) // Here's where the event is actually pushed
switch retVal {
case 1:
fmt.Println("PushEvent returned success")
case 0:
fmt.Println("PushEvent returned filtered")
case -1:
fmt.Printf("PushEvent returned error: %s\n", sdl.GetError)
}
}
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)
case *sdl.UserEvent:
fmt.Printf("[%d ms] UserEvent\tcode:%d\n", t.Timestamp, t.Code)
}
}
sdl.Delay(1000 / 30)
}
renderer.Destroy()
window.Destroy()
}