Documentation ¶
Overview ¶
Package input provides a flexible way to handle player inputs
Work in Progress ¶
The package is not feature-complete, but is advanced enough to handle most common cases.
Index ¶
- Constants
- func Err() error
- func GrabMouse(grab bool)
- func MouseGrabbed() bool
- func ShowMouse(show bool)
- type Action
- type AxisID
- type Bindings
- type ButtonID
- func (a ButtonID) Changed() bool
- func (a ButtonID) ChangedOn(d DeviceID) bool
- func (a ButtonID) Name() string
- func (a ButtonID) Ongoing() bool
- func (a ButtonID) OngoingOn(d DeviceID) bool
- func (a ButtonID) Pressed() bool
- func (a ButtonID) PressedOn(d DeviceID) bool
- func (a ButtonID) Released() bool
- func (a ButtonID) ReleasedOn(d DeviceID) bool
- type ContextID
- type CursorID
- type DeltaID
- type DeviceID
- type DualAxisID
- type HalfAxisID
Constants ¶
const ( Select = ButtonID(iota) Close Up Down Left Right Click Pointer = CursorID(0) )
Default actions with automatic bindings. If a context contain one of these, but no bindings is found, default bindings will be added. If there is no declared context, a default context will be created and include all these actions.
Variables ¶
This section is empty.
Functions ¶
func Err ¶
func Err() error
Err returns the first unchecked error of the package since last call to the function. The error is then considered checked, and further calls to Err will return nil until the next error occurs.
Note: errors occuring while there already is an unchecked error will not be recorded. However, if the debug mode is active, all errors will be logged.
func GrabMouse ¶
func GrabMouse(grab bool)
GrabMouse puts the mouse in relative mode: the cursor is hidden and cannot leave the game window, but the mouse movements (delta) are continuously reported, without constraints.
func MouseGrabbed ¶
func MouseGrabbed() bool
MouseGrabbed returns true if the relative mode is enabled.
Types ¶
type Action ¶
type Action interface {
// contains filtered or unexported methods
}
An Action represents something the player can do in the game. Actions can be bound to hardware input (by the player). During the game loop, actions can be queried and reacted upon.
type AxisID ¶
type AxisID uint32
AxisID identifies an absolute, one-dimensional analog action with a resting position and two directions, i.e. any action that is best represented by one floating-point value between -1 and +1.
type Bindings ¶
Bindings is a list of bindings for each context/action combination. The first map level associates each context name to a sub-map; this sub map then associates each action name to a slice of strings (the actual bindings).
type ButtonID ¶
type ButtonID uint32
ButtonID identifies a digital Action, i.e. an action that can be either "on" or "off".
In this package, the state of being "on" is called "pressed". The transition from "off" to "on" is called "pushed"; and the transition back to "off" is called "released".
func (ButtonID) Changed ¶
Changed returns true if the action has just been pressed or released this very frame (i.e. just been started or stopped by the player).
Note: this *must* be queried in the React method of the game loop, as this is the only method that is guaranteed to run at least once each frame.
func (ButtonID) ChangedOn ¶
ChangedOn returns true if the action has just been pressed or released this very frame (i.e. just been started or stopped by the player).
Note: this *must* be queried in the React method of the game loop, as this is the only method that is guaranteed to run at least once each frame.
func (ButtonID) Ongoing ¶
Ongoing returns true if the action has been started and is currently ongoing on the current device (i.e. it has been pressed but not released).
func (ButtonID) OngoingOn ¶
OngoingOn returns true if the action has been started and is currently ongoing on a specific device (i.e. it has been pressed but not released).
func (ButtonID) Pressed ¶
Pressed returns true if the action has just been started this very frame (i.e. just been pressed by the player).
Note: this *must* be queried in the React method of the game loop, as this is the only method that is guaranteed to run at least once each frame.
func (ButtonID) PressedOn ¶
PressedOn returns true if the action has just been started this very frame (i.e. just been pressed by the player).
Note: this *must* be queried in the React method of the game loop, as this is the only method that is guaranteed to run at least once each frame.
func (ButtonID) Released ¶
Released returns true if the action has just been stopped this very frame (i.e. just been released by the player).
Note: this *must* be queried in the React method of the game loop, as this is the only method that is guaranteed to run at least once each frame.
func (ButtonID) ReleasedOn ¶
ReleasedOn returns true if the action has just been stopped this very frame (i.e. just been released by the player).
Note: this *must* be queried in the React method of the game loop, as this is the only method that is guaranteed to run at least once each frame.
type ContextID ¶
type ContextID uint32
ContextID identifies an input context, i.e. a set of actions that can be active at the same time. The same action can be listed in several contexts, and have different (or identical) bindings in each.
func (ContextID) Activate ¶
func (a ContextID) Activate()
Activate makes the context active on all devices.
func (ContextID) ActivateOn ¶
ActivateOn makes the context active on a specific device.
type CursorID ¶
type CursorID uint32
CursorID identifes an absolute two-dimensional analog input, i.e. any action that is best represented by a pair of X and Y coordinates, and whose most important characteristic is the position in the game window.
type DeltaID ¶
type DeltaID uint32
DeltaID identifes a relative two-dimensional analog input, i.e. any action that is best represented by a pair of X and Y coordinates, and whose most important characteristic is the change in position.
type DeviceID ¶
type DeviceID uint32
DeviceID identifies an input device, i.e. any kind of hardware that can be bound to a game action.
Note: for convenience, the mouse and keyboard are considered to be the same device, and share the same ID.
const ( // KeyboardAndMouse is the only device that doesn't need to be declared KeyboardAndMouse DeviceID = 0 )
func CurrentDevice ¶
func CurrentDevice() DeviceID
CurrentDevice returns the device most recently used
type DualAxisID ¶
type DualAxisID uint32
DualAxisID identifies an absolute two-dimensional analog action, i.e. any action that is best represented by a pair of X and Y coordinates, and whose most important characteristic is the current position. The values of the coordinates are normalized between -1 and 1.
func DualAxis ¶
func DualAxis(name string) DualAxisID
DualAxis declares a new two-dimensional analog action, and returns its ID.
func (DualAxisID) XY ¶
func (a DualAxisID) XY() coord.XY
XY returns the current status of the action on the current device. The coordinates are the current absolute position; the values of X and Y are normalized between -1 and 1.
type HalfAxisID ¶
type HalfAxisID uint32
HalfAxisID identifies an absolute, one-dimensional analog action with a resting position and one signle direction, i.e. any action that is best represented by one floating-point value between 0 and 1.
func HalfAxis ¶
func HalfAxis(name string) HalfAxisID
HalfAxis declares a new unipolar analog action, and returns its ID.
func (HalfAxisID) Value ¶
func (a HalfAxisID) Value() float32
Value returns the current value of the action on the current device. This value is normalized between 0 and 1.
func (HalfAxisID) ValueOn ¶
func (a HalfAxisID) ValueOn(d DeviceID) float32
ValueOn returns the current value of the action on a specific device. This value is normalized between 0 and 1.
Source Files ¶
- action.go
- axis.go
- bind.go
- binders.go
- button.go
- context.go
- cursor.go
- delta.go
- device.go
- doc.go
- dualaxis.go
- error.go
- gpaxis.go
- gpbutton.go
- gpstick.go
- gptrigger.go
- halfaxis.go
- joysticks.go
- kbkey.go
- keycodes.go
- keylabels.go
- mouse.go
- msaxis.go
- msbutton.go
- mscoord.go
- mswheel.go
- newframe.go
- setup.go
- source.go