From 03cd1562fddd64f71ac5348f4664ecb7aba22bed Mon Sep 17 00:00:00 2001 From: Joshua Salzedo Date: Tue, 10 Mar 2020 07:50:16 -0700 Subject: [PATCH] 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. --- examples/joystick-input/joystick-input.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/joystick-input/joystick-input.go b/examples/joystick-input/joystick-input.go index 98e3e7b..c1475fe 100644 --- a/examples/joystick-input/joystick-input.go +++ b/examples/joystick-input/joystick-input.go @@ -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") }