Fixed init and button detection runtime (#7)
The JoyButtonEvent handler incorrectly checked the t.Type rather than the T.State when deciding whether a button was pressed or released. The joystick constructor was missing an int cast.
This commit is contained in:
parent
756f6fc108
commit
03cd1562fd
|
@ -37,7 +37,7 @@ func run() (err error) {
|
|||
case *sdl.JoyBallEvent:
|
||||
fmt.Println("Joystick", t.Which, "trackball moved by", t.XRel, t.YRel)
|
||||
case *sdl.JoyButtonEvent:
|
||||
if t.Type == sdl.PRESSED {
|
||||
if t.State == sdl.PRESSED {
|
||||
fmt.Println("Joystick", t.Which, "button", t.Button, "pressed")
|
||||
} else {
|
||||
fmt.Println("Joystick", t.Which, "button", t.Button, "released")
|
||||
|
@ -69,7 +69,7 @@ func run() (err error) {
|
|||
fmt.Println("Joystick", t.Which, "hat", t.Hat, "moved to", position, "position")
|
||||
case *sdl.JoyDeviceAddedEvent:
|
||||
// Open joystick for use
|
||||
joysticks[int(t.Which)] = sdl.JoystickOpen(t.Which)
|
||||
joysticks[int(t.Which)] = sdl.JoystickOpen(int(t.Which))
|
||||
if joysticks[int(t.Which)] != nil {
|
||||
fmt.Println("Joystick", t.Which, "connected")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue