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:
|
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")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue