Class: Input

Input


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
Name Type Argument Description
canvasFit Boolean <optional>

Set to true if using css to fit the canvas in the viewport

listenForMouse Boolean <optional>

Whether or not to listen for mouse events

listenForTouch Boolean <optional>

Whether or not to listen for touch events

listenForKeyboard Boolean <optional>

Whether or not to listen for keyboard events

window Object <optional>

window object for testing

document Object <optional>

document object for testing

Author:
  • Chris Peters
Source:
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

Source:
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]

Source:
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

Source:

addListener(type, handler, target)

Adds a handler to a Sprite for the given event type

Parameters:
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

Source:
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 }

Source:
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

Source:
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

Source: