Constructor
new Controller(elementopt, optionsopt)
Create a new instance of a Controller.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
element |
Element |
<optional> |
Element to attach Controller to. | ||||||||||||||||
options |
Object |
<optional> |
Optional arguments.
Properties
|
- Source:
Example
var c = new pc.Controller(document)
// Register the "fire" action and assign it to both the Enter key and the Spacebar.
c.registerKeys("fire", [pc.KEY_ENTER, pc.KEY_SPACE]);
Methods
attach(element)
Attach Controller to a Element, this is required before you can monitor for key/mouse inputs.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | The element to attach mouse and keyboard event handler too |
- Source:
detach()
Detach Controller from an Element, this should be done before the Controller is destroyed
- Source:
disableContextMenu()
Disable the context menu usually activated with the right mouse button.
- Source:
enableContextMenu()
Enable the context menu usually activated with the right mouse button. This is enabled by default.
- Source:
isPressed(actionName) → {Boolean}
Returns true if the current action is enabled.
Parameters:
Name | Type | Description |
---|---|---|
actionName |
String | The name of the action. |
- Source:
Returns:
True if the action is enabled.
- Type
- Boolean
registerAxis(optionsopt)
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Optional options object.
Properties
|
- Source:
registerKeys(action, keys)
Create or update a action which is enabled when the supplied keys are pressed.
Parameters:
Name | Type | Description |
---|---|---|
action |
String | The name of the action |
keys |
Array.<Number> | A list of keycodes |
- Source:
registerMouse(action, button)
Create or update an action which is enabled when the supplied mouse button is pressed
Parameters:
Name | Type | Description |
---|---|---|
action |
String | The name of the action |
button |
Number | The mouse button |
- Source:
registerPadButton(action, pad, button)
Create or update an action which is enabled when the gamepad button is pressed
Parameters:
Name | Type | Description |
---|---|---|
action |
String | The name of the action |
pad |
Number | The index of the pad to register (use pc.PAD_1, etc) |
button |
Number | The pad button |
- Source:
update(dt)
Update the Keyboard and Mouse handlers
Parameters:
Name | Type | Description |
---|---|---|
dt |
Object | The time since the last frame |
- Source:
wasPressed(actionName) → {Boolean}
Returns true if the action was enabled this since the last update.
Parameters:
Name | Type | Description |
---|---|---|
actionName |
String | The name of the action. |
- Source:
Returns:
True if the action was enabled this since the last update.
- Type
- Boolean