I'm trying to do this:
if event.Type == sdl.QUIT {
utils.Running = false
}
But I can't because when I try to build, I get this error:
./mm.go:11: event.Type undefined (type sdl.Event has no field or method Type)
Here is the relevant source code of the library I'm trying to use:
type Event interface{}
type CEvent struct {
Type uint32
_ [52]byte // padding
}
type CommonEvent struct {
Type uint32
Timestamp uint32
}
// WindowEvent (https://wiki.libsdl.org/SDL_WindowEvent)
type WindowEvent struct {
Type uint32
Timestamp uint32
WindowID uint32
Event uint8
_ uint8 // padding
_ uint8 // padding
_ uint8 // padding
Data1 int32
Data2 int32
}
As you can see, all of the other Events have the field Type
. How can I access this?
Solution
This how I ended up polling events in this SDL2 binding for Go, in case anyone is wondering:
func PollEvents() {
for {
if event := sdl.PollEvent(); event != nil {
switch event.(type) {
case *sdl.QuitEvent:
utils.Running = false
}
} else {
break
}
}
}