Q.InputSystem Class
Button and mouse input subsystem for Quintus. An instance of this class is auto-created as Q.input
Item Index
Methods
bindKey
-
key
-
name
Bind a key name or keycode to an action name (used by keyboardControls
)
Parameters:
-
key
String or Integer- name or integer keycode for to bind
-
name
String- name of action to bind to
debind
()
debind
is called to remove any listeners an object had
on other objects. The most common case is when an object is
destroyed you'll want all the event listeners to be removed
for you.
disableMouseControls
()
Turn off mouse controls
disableTouchControls
()
Turn off touch (buytton and joypad) controls and remove event listeners
drawButtons
()
Draw the touch buttons on the screen
overload this to change how buttons are drawn
drawCanvas
()
Called each frame by the stage game loop to render any onscreen UI
calls drawJoypad
and drawButtons
if enabled
drawJoypad
()
Draw the joypad on the screen
overload this to change how joypad is drawn
enableKeyboard
()
Enable keyboard controls by binding to events
extend
-
className
-
properties
-
[classMethods]
Create a new Class that inherits from this class
Parameters:
-
className
String -
properties
Object- hash of properties (init will be the constructor)
-
[classMethods]
Object optional- optional class methods to add to the class
isA
-
className
See if a object is a specific class
Parameters:
-
className
String- class to check against
joypadControls
-
[opts]
Activate joypad controls (i.e. 4-way touch controls)
Lots of options, defaults are:
{
size: 50,
trigger: 20,
center: 25,
color: "#CCC",
background: "#000",
alpha: 0.5,
zone: Q.width / 2,
inputs: DEFAULT_JOYPAD_INPUTS
}
Default joypad controls is an array that defines the inputs to bind to:
// Clockwise from midnight (a la CSS)
var DEFAULT_JOYPAD_INPUTS = [ 'up','right','down','left'];
Parameters:
-
[opts]
Object optional- joypad options
keyboardControls
-
[keys]
Convenience method to activate keyboard controls (call bindKey
and enableKeyboard
internally)
Parameters:
-
[keys]
Object optional- hash of key names or codes to actions
mouseControls
-
[options]
Activate mouse controls - mouse controls don't trigger events, but just set Q.inputs[mouseX]
& Q.inputs['mouseY']
on each frame.
Default options:
{
stageNum: 0,
mouseX: "mouseX",
mouseY: "mouseY",
cursor: "off"
}
Parameters:
-
[options]
Object optional- override default options
off
-
event
-
[target]
-
[callback]
Unbinds an event. Can be called with 1, 2, or 3 parameters, each of which unbinds a more specific listener.
Parameters:
-
event
String- name of event
-
[target]
Object optional- optionally limit to a specific target
-
[callback]
Function optional- optionally limit to one specific callback
on
-
event
-
[target]
-
[callback]
Binds a callback to an event on this object. If you provide a
target
object, that object will add this event to it's list of
binds, allowing it to automatically remove it when it is destroyed.
Parameters:
-
event
String- name or comma separated list of events
-
[target]
Object optional- optional context for callback, defaults to the Evented
-
[callback]
Function optional- callback (optional - defaults to name of event on context
touchControls
-
[opts]
Activate touch button controls - pass in an options hash to override
Default Options:
{
left: 0,
gutter:10,
controls: DEFAULT_TOUCH_CONTROLS,
width: Q.width,
bottom: Q.height
}
Default controls are left and right buttons, a space, and 'a' and 'b' buttons, as defined as an Array of Arrays below:
[ ['left','<' ],
['right','>' ],
[], // use an empty array as a spacer
['action','b'],
['fire', 'a' ]]
Parameters:
-
[opts]
Object optional- Options hash
trigger
-
event
-
[data]
Triggers an event, passing in some optional additional data about the event.
Parameters:
-
event
String- name of event
-
[data]
Object optional- optional data to pass to the callback