Documentation ¶
Index ¶
- Constants
- Variables
- func ConnectMouse()
- func DisconnectMouse()
- func IsKeyboardFree() bool
- func MouseButton(index int) bool
- func MouseDelta() (float64, float64)
- func MousePosition() (float64, float64)
- func MouseScroll() (float64, float64)
- func RegisterKeyCallback(callback glfw.KeyCallback)
- func UnregisterKeyCallback()
- func UpdateCameraWithMouse(camera *graphics.Camera2D)
- type ControllerAxis
- type ControllerButton
- type GameController
- type GameControllerMapping
- type JoystickController
- func (c *JoystickController) AxisDigitalValue(axis ControllerAxis) int
- func (c *JoystickController) AxisValue(axis ControllerAxis) float64
- func (c *JoystickController) ButtonDown(button ControllerButton) bool
- func (c *JoystickController) ButtonPressed(button ControllerButton) bool
- func (c *JoystickController) ButtonReleased(button ControllerButton) bool
- func (c *JoystickController) Close()
- func (c *JoystickController) Connected() bool
- func (c *JoystickController) Description() string
- func (c *JoystickController) NumAxes() int
- func (c *JoystickController) NumButtons() int
- func (c *JoystickController) Open(deviceIndex int) bool
- func (c *JoystickController) SetMapping(mapping *GameControllerMapping)
- func (c *JoystickController) Update()
- type KeyboardController
- func (c *KeyboardController) AxisDigitalValue(axis ControllerAxis) int
- func (c *KeyboardController) AxisValue(axis ControllerAxis) float64
- func (c *KeyboardController) ButtonDown(button ControllerButton) bool
- func (c *KeyboardController) ButtonPressed(button ControllerButton) bool
- func (c *KeyboardController) ButtonReleased(button ControllerButton) bool
- func (c *KeyboardController) Close()
- func (c *KeyboardController) Connected() bool
- func (c *KeyboardController) Description() string
- func (c *KeyboardController) NumAxes() int
- func (c *KeyboardController) NumButtons() int
- func (c *KeyboardController) Open(_ int) bool
- func (c *KeyboardController) SetMapping(mapping *GameControllerMapping)
- func (c *KeyboardController) Update()
Constants ¶
const ( ButtonA ControllerButton = iota ButtonB ButtonX ButtonY ButtonBack ButtonGuide ButtonStart ButtonLeftStick ButtonRightStick ButtonLeftShoulder ButtonRightShoulder ButtonDirPadUp ButtonDirPadDown ButtonDirPadLeft ButtonDirPadRight AxisLeftX ControllerAxis = iota AxisLeftY AxisRightX AxisRightY AxisTriggerLeft AxisTriggerRight // MaxNumJoysticks max num of joysticks allowed by glfw MaxNumJoysticks = glfw.JoystickLast )
Constants for all the buttons and axes
Variables ¶
var (
JoystickControllers map[int]*JoystickController
)
Functions ¶
func ConnectMouse ¶
func ConnectMouse()
ConnectMouse Registers the callbacks and starts receiving the mouse's events
func DisconnectMouse ¶
func DisconnectMouse()
DisconnectMouse Unregisters the callbacks and stops receiving the mouse's events
func IsKeyboardFree ¶
func IsKeyboardFree() bool
func MouseButton ¶
MouseButton Returns the state of the specified mouse button
func MouseDelta ¶
MouseDelta Returns the latest movement of the cursor
func MousePosition ¶
MousePosition Returns the coordinates of the cursor's position
func MouseScroll ¶
MouseScroll Returns the last wheel's scroll offsets
func RegisterKeyCallback ¶
func RegisterKeyCallback(callback glfw.KeyCallback)
func UnregisterKeyCallback ¶
func UnregisterKeyCallback()
func UpdateCameraWithMouse ¶
Types ¶
type ControllerAxis ¶
type ControllerAxis int
ControllerAxis type representing an axis of the input device
type ControllerButton ¶
type ControllerButton int
ControllerButton type representing a button of the input device
type GameController ¶
type GameController interface { Connected() bool Open(deviceIndex int) bool Close() Update() NumButtons() int NumAxes() int ButtonPressed(button ControllerButton) bool ButtonReleased(button ControllerButton) bool ButtonDown(button ControllerButton) bool AxisValue(axis ControllerAxis) float64 AxisDigitalValue(axis ControllerAxis) int SetMapping(mapping *GameControllerMapping) Description() string }
GameController represents a physical input device
type GameControllerMapping ¶
type GameControllerMapping struct {
// contains filtered or unexported fields
}
GameControllerMapping a axes/buttons mapping for a specific device
var ( GameControllerMappings []*GameControllerMapping MappingXBox360 GameControllerMapping MappingPS4 GameControllerMapping MappingKeyboard GameControllerMapping )
A set of basic mappings
type JoystickController ¶
type JoystickController struct { GameController // contains filtered or unexported fields }
func (*JoystickController) AxisDigitalValue ¶
func (c *JoystickController) AxisDigitalValue(axis ControllerAxis) int
func (*JoystickController) AxisValue ¶
func (c *JoystickController) AxisValue(axis ControllerAxis) float64
func (*JoystickController) ButtonDown ¶
func (c *JoystickController) ButtonDown(button ControllerButton) bool
func (*JoystickController) ButtonPressed ¶
func (c *JoystickController) ButtonPressed(button ControllerButton) bool
func (*JoystickController) ButtonReleased ¶
func (c *JoystickController) ButtonReleased(button ControllerButton) bool
func (*JoystickController) Close ¶
func (c *JoystickController) Close()
func (*JoystickController) Connected ¶
func (c *JoystickController) Connected() bool
func (*JoystickController) Description ¶
func (c *JoystickController) Description() string
func (*JoystickController) NumAxes ¶
func (c *JoystickController) NumAxes() int
func (*JoystickController) NumButtons ¶
func (c *JoystickController) NumButtons() int
func (*JoystickController) Open ¶
func (c *JoystickController) Open(deviceIndex int) bool
func (*JoystickController) SetMapping ¶
func (c *JoystickController) SetMapping(mapping *GameControllerMapping)
func (*JoystickController) Update ¶
func (c *JoystickController) Update()
type KeyboardController ¶
type KeyboardController struct { GameController // contains filtered or unexported fields }
KeyboardController A GameController that uses the keyboard to simulate a joystick
func (*KeyboardController) AxisDigitalValue ¶
func (c *KeyboardController) AxisDigitalValue(axis ControllerAxis) int
AxisDigitalValue returns a digital value for the axis
func (*KeyboardController) AxisValue ¶
func (c *KeyboardController) AxisValue(axis ControllerAxis) float64
AxisValue returns the current value, from -1 to 1, of the axis
func (*KeyboardController) ButtonDown ¶
func (c *KeyboardController) ButtonDown(button ControllerButton) bool
ButtonDown checks if a button is currently pressed
func (*KeyboardController) ButtonPressed ¶
func (c *KeyboardController) ButtonPressed(button ControllerButton) bool
ButtonPressed checks if a button has been pressed since the last frame
func (*KeyboardController) ButtonReleased ¶
func (c *KeyboardController) ButtonReleased(button ControllerButton) bool
ButtonReleased checks if a button has been released since the last frame
func (*KeyboardController) Close ¶
func (c *KeyboardController) Close()
Close disables the keyboard callback and resets all the data
func (*KeyboardController) Connected ¶
func (c *KeyboardController) Connected() bool
Connected returns if this controller is connected and initialized
func (*KeyboardController) Description ¶
func (c *KeyboardController) Description() string
Description identification string of this controller
func (*KeyboardController) NumAxes ¶
func (c *KeyboardController) NumAxes() int
NumAxes number of the axes this controller is simulating
func (*KeyboardController) NumButtons ¶
func (c *KeyboardController) NumButtons() int
NumButtons number of the buttons this controller is simulating
func (*KeyboardController) Open ¶
func (c *KeyboardController) Open(_ int) bool
Open initializes the keyboard. The parameter is ignored
func (*KeyboardController) SetMapping ¶
func (c *KeyboardController) SetMapping(mapping *GameControllerMapping)
SetMapping maps the keys to the virtual controller inputs
func (*KeyboardController) Update ¶
func (c *KeyboardController) Update()
Update gets the input from the keyboard and sets the game controller accordingly