Module: Input

Various functions to help with user input

Source:

Members

(static) cursorKeys :number

The cursor key values. Can be used to register keys

Type:
  • number
Properties:
Name Type Description
kLeft number
kRight number
kUp number
kDown number
Source:

(static, constant) kASWDKeys :Array.<number>

You can use these to make your own options for setupKeyboardDPadKeys

Type:
  • Array.<number>
Source:

(static, constant) kASWDPadOnly :module:Input.DPadKeys~Options

You can use these to make your own options for setupKeyboardDPadKeys

Input.setupKeyboardDPadKeys(callback, Input.kASWDPadOnly);
Type:
Source:

(static, constant) kCursorKeys :Array.<number>

You can use these to make your own options for setupKeyboardDPadKeys

Type:
  • Array.<number>
Source:

(static, constant) kCursorPadOnly :module:Input.DPadKeys~Options

You can use these to make your own options for setupKeyboardDPadKeys

Input.setupKeyboardDPadKeys(callback, Input.kCursorPadOnly);
Type:
Source:

Methods

(static) createDirectionEventInfo() → {module:Input.EventInfo}

Creates an EventInfo for a given padId

Source:
Returns:
Type
module:Input.EventInfo

(static) emitDirectionEvent(padId, direction, eventInfo, callback)

Parameters:
Name Type Description
padId number

id of pad. eg. 0, 1, 2

direction number

direction pad is being pressed -1 to 7.

eventInfo EventInfo

from createDirectionEventInfo.

callback callback

to pass eventInfo once it's been filled out.

Source:

(static) getDirectionInfo(direction) → {module:Input.DirectionInfo}

Given a direction returns a direction info

Parameters:
Name Type Description
direction number

1 to 7

Source:
Returns:
Type
module:Input.DirectionInfo

(static) getRelativeCoordinates(reference, event) → {module:Input.Coordinate}

Gets the relative coordinates for an event

Parameters:
Name Type Description
reference HTMLElement

html elemetn to reference

event Event

from HTML mouse event

Source:
Returns:

the relative position

Type
module:Input.Coordinate

(static) setupControllerKeys(keyDownFn, keyUpFn)

Sets up controller key functions

Parameters:
Name Type Description
keyDownFn callback(code, down)

a function to be called when a key is pressed. It's passed the keycode and true.

keyUpFn callback(code, down)

a function to be called when a key is released. It's passed the keycode and false.

Source:

(static) setupKeyboardDPadKeys(callback, optionsnullable)

Simulates N virtual dpads using keys asdw for pad 0, arrow keys for pad 1

For each change in direction callback will be called with pad id (0 left, 1 right) and direction where

   2     -1 = not pressed
 3 | 1
  \|/
4--+--0
  /|\
 5 | 7
   6

Note: this matches trig functions you can do this

var angle = dir * Math.PI / 4;
var dx    = Math.cos(angle);
var dy    = Math.sin(angle);

for +y up (ie, normal for 3d)

In 2d you'd probably want

var angle =  dir * Math.PI / 4;
var dx    =  Math.cos(angle);
var dy    = -Math.sin(angle);
Parameters:
Name Type Attributes Description
callback callback

callback will be called with EventInfo objects when pads change their direction

options module:Input.DPadKeys~Options <nullable>

If no options are passed in assumes 2 DPads one on ASWD the other on the cursor keys

Source:

(static) setupKeys(array)

Sets up handlers for specific keys

Parameters:
Name Type Description
array Object.<string, callback>

of keys to handler functions. Handlers are called with a KeyEvent

Source:
Example
var keys = { };
     keys["Z".charCodeAt(0)] = handleJump;
     keys["X".charCodeAt(0)] = handleShow
     keys["C".charCodeAt(0)] = handleTestSound;
     keys[Input.cursorKeys.kRight] = handleMoveRight;
     Input.setupKeys(keys);

Type Definitions

Coordinate

Type:
  • Object
Properties:
Name Type Description
x number

the x coordinate

y number

the y coordinate

Source:

DirectionInfo

Various info for a given 8 direction direction.

   2     -1 = no touch
 3 | 1
  \|/
4--+--0
  /|\
 5 | 7
   6
Type:
  • Object
Properties:
Name Type Description
direction number

1 to 7

dx number

1, 0, or 1

dy number

1, 0, or 1

bits number

where R = 0x1, L = 0x2, U = 0x4, D = 0x8

unicode string

arrow simple for direction.

Source:

DPadKeys

Type:
  • Object
Properties:
Name Type Description
keys Array.<number>

Array of 4 key codes that make a keyboard dpad in LRUD order.

Source:

EventInfo

Type:
  • Object
Properties:
Name Type Description
pad number

the pad id 0, 1, 2, etc.

info module:Input.DirectionInfo

the direction info for the event.

Source:

KeyEvent

Type:
  • Object
Properties:
Name Type Description
keyCode number
pressed boolean

true if pressed, false if released

Source: