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:
Joshua Salzedo 2020-03-10 07:50:16 -07:00 committed by GitHub
parent 756f6fc108
commit 03cd1562fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -37,7 +37,7 @@ func run() (err error) {
case *sdl.JoyBallEvent: case *sdl.JoyBallEvent:
fmt.Println("Joystick", t.Which, "trackball moved by", t.XRel, t.YRel) fmt.Println("Joystick", t.Which, "trackball moved by", t.XRel, t.YRel)
case *sdl.JoyButtonEvent: case *sdl.JoyButtonEvent:
if t.Type == sdl.PRESSED { if t.State == sdl.PRESSED {
fmt.Println("Joystick", t.Which, "button", t.Button, "pressed") fmt.Println("Joystick", t.Which, "button", t.Button, "pressed")
} else { } else {
fmt.Println("Joystick", t.Which, "button", t.Button, "released") 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") fmt.Println("Joystick", t.Which, "hat", t.Hat, "moved to", position, "position")
case *sdl.JoyDeviceAddedEvent: case *sdl.JoyDeviceAddedEvent:
// Open joystick for use // 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 { if joysticks[int(t.Which)] != nil {
fmt.Println("Joystick", t.Which, "connected") fmt.Println("Joystick", t.Which, "connected")
} }