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 xInteger [description]
yInteger [description]
boundingBoxObject [description]
Returns:
- Type
- Boolean
-
_onTick(e)
-
Triggers all queued events. Passes the factor and ticks from
TickerParameters:
Name Type Description eObject The event object
-
addListener(type, handler, target)
-
Adds a handler to a
Spritefor the given event typeParameters:
Name Type Argument Description typestring The event type
handlerfunction The function to execute when event triggered
targetobject <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 typestring the event type
handlerfunction 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 fnfunction The user's hit test method