new Input(canvas, opts)
A module for handling keyboard, mouse, and touch events on the canvas
Parameters:
Name | Type | Argument | Description | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
canvas |
HTMLEntity | The canvas element to interact with |
|||||||||||||||||||||||||||||
opts |
Object |
<optional> |
Properties
|
Requires:
- module:Radio
- module:lib/keycodes
Requires
- module:Radio
- module:lib/keycodes
Methods
-
_getScaleFactor()
-
get the scale ratio of the canvas based on with/heght attrs and css width/height
Returns:
- Type
- Float
-
_hitTest(x, y, boundingBox)
-
Checks if point is inside rectangle
Parameters:
Name Type Description x
Integer [description]
y
Integer [description]
boundingBox
Object [description]
Returns:
- Type
- Boolean
-
_onTick(e)
-
Triggers all queued events. Passes the factor and ticks from
Ticker
Parameters:
Name Type Description e
Object The event object
-
addListener(type, handler, target)
-
Adds a handler to a
Sprite
for the given event typeParameters:
Name Type Argument Description type
string The event type
handler
function The function to execute when event triggered
target
object <optional>
The target to check event trigger against
Returns:
Returns true if added and false if callback already exists
- Type
- boolean
-
getKeysDown()
-
returns an object of the keys currently being pressed
eg:{ LEFT_ARROW: 37, UP_ARROW: 38 }
Returns:
- Type
- Object
-
removeListener(type, handler)
-
Removes matching handler if found
Parameters:
Name Type Description type
string the event type
handler
function the handler to remove
Returns:
removed Returns true if removed and otherwise false
- Type
- boolean
-
setHitTestMethod(fn)
-
Allows user to set a custom hit test method
Parameters:
Name Type Description fn
function The user's hit test method