Documentation ¶
Overview ¶
Package controller lets you poll controllers, their buttons their axes and let them rumble.
Index ¶
Constants ¶
const ( AxisLeftX = Axis(sdl.CONTROLLER_AXIS_LEFTX) AxisLeftY = Axis(sdl.CONTROLLER_AXIS_LEFTY) AxisRightX = Axis(sdl.CONTROLLER_AXIS_RIGHTX) AxisRightY = Axis(sdl.CONTROLLER_AXIS_RIGHTY) AxisTriggerLeft = Axis(sdl.CONTROLLER_AXIS_TRIGGERLEFT) AxisTriggerRight = Axis(sdl.CONTROLLER_AXIS_TRIGGERRIGHT) )
All a possible axes.
const ( ButtonA = Button(sdl.CONTROLLER_BUTTON_A) ButtonB = Button(sdl.CONTROLLER_BUTTON_B) ButtonX = Button(sdl.CONTROLLER_BUTTON_X) ButtonY = Button(sdl.CONTROLLER_BUTTON_Y) ButtonBack = Button(sdl.CONTROLLER_BUTTON_BACK) ButtonGuide = Button(sdl.CONTROLLER_BUTTON_GUIDE) ButtonStart = Button(sdl.CONTROLLER_BUTTON_START) ButtonLeftStick = Button(sdl.CONTROLLER_BUTTON_LEFTSTICK) ButtonRightStick = Button(sdl.CONTROLLER_BUTTON_RIGHTSTICK) ButtonLeftShoulder = Button(sdl.CONTROLLER_BUTTON_LEFTSHOULDER) ButtonRightShoulder = Button(sdl.CONTROLLER_BUTTON_RIGHTSHOULDER) ButtonDPadUp = Button(sdl.CONTROLLER_BUTTON_DPAD_UP) ButtonDPadDown = Button(sdl.CONTROLLER_BUTTON_DPAD_DOWN) ButtonDPadLeft = Button(sdl.CONTROLLER_BUTTON_DPAD_LEFT) ButtonDPadRight = Button(sdl.CONTROLLER_BUTTON_DPAD_RIGHT) )
All possible buttons.
Variables ¶
var All = map[sdl.JoystickID]*Controller{}
All contains all available controllers.
Functions ¶
func DispatchAxisEvent ¶
func DispatchAxisEvent(id sdl.JoystickID, a uint8, value int16)
DispatchAxisEvent triggers an axis event. This func should not be called manually.
func DispatchButtonEvent ¶
func DispatchButtonEvent(id sdl.JoystickID, b uint8, state uint8)
DispatchButtonEvent triggers a button event. This func should not be called manually.
Types ¶
type Controller ¶
type Controller struct { ID int Name string Connected bool // contains filtered or unexported fields }
Controller is a Controller, Gamepad or Joystick.
func Close ¶
func Close(id sdl.JoystickID) *Controller
Close closes the joystick for the given id and returns the now disconnected controller.
func Open ¶
func Open(id sdl.JoystickID) *Controller
Open opens the joystick for the given id and returns it.
func (*Controller) ClearListener ¶
func (c *Controller) ClearListener()
ClearListener removes the Listener for the controller.
func (*Controller) Rumble ¶
func (c *Controller) Rumble(strength float32, duration uint32) error
Rumble lets the controller vibrate for a given time and strength.
func (*Controller) SetListener ¶
func (c *Controller) SetListener(l *Listener)
SetListener sets the Listener that will get notified when controller events occur.
type Listener ¶
type Listener struct { // OnButtonDown gets called when a button is pressed. OnButtonDown func(b Button) // OnButtonUp gets called when a button is released. OnButtonUp func(b Button) // OnAxisMoved gets called when a axis is moved. OnAxisMoved func(a Axis, value float64) // OnConnect gets called when the controller connects. OnConnect func() // OnDisconnectConnect gets called when the controller disconnects. OnDisconnect func() }
Listener is used as a scaffold to listen to controller events.