InputHandler
Simple yet powerful input handler.
Example:
const component = new InputHandler();
component.deserialize({ requireGamepad: true });
Static Member Summary
Static Public Members | ||
public static get |
|
|
public static get |
propsTypes: * |
Static Method Summary
Static Public Methods | ||
public static |
Component factory. |
Constructor Summary
Public Constructor | ||
public |
Constructor. |
Member Summary
Public Members | ||
public get |
|
|
public set |
|
|
public get |
|
|
public set |
|
|
public get |
|
|
public set |
|
|
public get |
|
|
public set |
|
|
public get |
axes: * |
|
public get |
|
|
public set |
|
|
public get |
|
|
public set |
|
|
public get |
|
|
public get |
|
|
public get |
|
|
public |
listenTo: * |
|
public get |
|
|
public set |
|
|
public get |
|
|
public set |
|
|
public get |
triggers: * |
Method Summary
Public Methods | ||
public |
acquireGamepad(trigger: number, timeout: number): Promise Asynchronously acquire gamepad (specify trigger to press and waiting duration). |
|
public |
clear() Clear all axes, triggers and configs. |
|
public |
dispose() |
|
public |
getAcquiredGamepad(): Gamepad | null Get acquired gamepad instance. |
|
public |
Get value of given axis. |
|
public |
getAxisDelta(id: string): number Get delta value of given axis. |
|
public |
getTrigger(id: string, treshold: number): number Get value of given trigger. |
|
public |
getTriggerDelta(id: string): number Get delta value of given trigger. |
|
public |
isAxisHold(id: string, treshold: number): boolean Tells if axis is currently hold. |
|
public |
isAxisPressed(id: string, treshold: number): boolean Tells if axis is pressed in current frame. |
|
public |
isAxisReleased(id: string, treshold: number): boolean Tells if axis is released in current frame. |
|
public |
isTriggerHold(id: string, treshold: number): boolean Tells if trigger is currently hold. |
|
public |
isTriggerPressed(id: string, treshold: number): boolean Tells if trigger is pressed in current frame. |
|
public |
isTriggerReleased(id: string, treshold: number): boolean Tells if trigger is released in current frame. |
|
public |
onAttach() |
|
public |
onDetach() |
|
public |
onGamepadConnected(gamepad: *) |
|
public |
onGamepadDisconnected(gamepad: *) |
|
public |
onGamepadProcess(gamepad: *) |
|
public |
onKeyDown(code: *) |
|
public |
onKeyUp(code: *) |
|
public |
onMouseDown(unitVec: *, screenVec: *, button: *) |
|
public |
onMouseMove(unitVec: *, screenVec: *) |
|
public |
onMouseUp(unitVec: *, screenVec: *, button: *) |
|
public |
onUpdate(deltaTime: *) |
|
public |
Release acquired gamepad. |
|
public |
setAcquiredGamepad(index: number) Manually acquire gamepad by it's index. |
|
public |
Set given axis value. |
|
public |
setTrigger(id: string, value: number) Set given trigger value. |
|
public |
setup(config: *) Setup axes and triggers. |
Inherited Summary
From class Component | ||
public static get |
propsTypes: * |
|
public static |
Component factory. |
|
public get |
|
|
public |
[name]: * |
|
public |
deserialize(json: *) Deserialize JSON properties into this component. |
|
public |
dispose() Destructor (dispose internal resources and detach from entity). |
|
public |
Called when action arrived. |
|
public |
onAlterActionArguments(name: string, args: *): array | undefined Called when asked to alter arrived action parameters. |
|
public |
onAttach() Called after attached to entity. |
|
public |
onDetach() Called before detached from entity. |
|
public |
onPropertySerialize(name: string, value: *): * Called when property is serialized. |
|
public |
onPropertySetup(name: string, value: *) Called when given property is deserialized. |
|
public |
serialize(): * Serialize component into JSON data. |
From class Script | ||
public static get |
EventFlags: * |
|
public static get |
propsTypes: {"listenTo": *} |
|
public static |
factory(): * |
|
public get |
listenTo: * |
|
public set |
|
|
public |
dispose() |
|
public |
onAction(name: *, args: ...*): * |
|
public |
onAttach() |
|
public |
onContactBegin(body: *, contact: *) |
|
public |
onContactEnd(body: *, contact: *) |
|
public |
onDetach() |
|
public |
onGamepadConnected(gamepad: *) |
|
public |
onGamepadDisconnected(gamepad: *) |
|
public |
onGamepadProcess(gamepad: *) |
|
public |
onKeyDown(code: *) |
|
public |
onKeyUp(code: *) |
|
public |
onMouseDown(unitVec: *, screenVec: *, button: *) |
|
public |
onMouseMove(unitVec: *, screenVec: *) |
|
public |
onMouseUp(unitVec: *, screenVec: *, button: *) |
|
public |
onPreview(gl: *, renderer: *, deltaTime: *) |
|
public |
onPropertySerialize(name: *, value: *): * |
|
public |
onPropertySetup(name: *, value: *) |
|
public |
onRender(gl: *, renderer: *, deltaTime: *, layer: *) |
|
public |
onRenderLayer(gl: *, renderer: *, deltaTime: *, layer: *) |
|
public |
onTouchDown(unitVec: *, screenVec: *, identifier: *) |
|
public |
onTouchMove(unitVec: *, screenVec: *, identifier: *) |
|
public |
onTouchUp(unitVec: *, screenVec: *, identifier: *) |
|
public |
onUpdate(deltaTime: *) |
Static Public Members
public static get ControlDevice: * source
Static Public Methods
Public Constructors
Public Methods
public acquireGamepad(trigger: number, timeout: number): Promise source
Asynchronously acquire gamepad (specify trigger to press and waiting duration).
Example:
component.acquireGamepad(0).then(() => System.events.trigger('player-is-ready'));
public dispose() source
Destructor (dispose internal resources and detach from entity).
Override:
Script#disposepublic getAxis(id: string, treshold: number): number source
Get value of given axis.
Example:
x += component.getAxis('pos-x');
public getAxisDelta(id: string): number source
Get delta value of given axis.
Params:
Name | Type | Attribute | Description |
id | string | Axis id. |
Example:
if (component.getAxisDelta('pos-y') < 0) { entity.performAction('jump'); }
public getTrigger(id: string, treshold: number): number source
Get value of given trigger.
Example:
speed += component.getTrigger('accel');
public getTriggerDelta(id: string): number source
Get delta value of given trigger.
Params:
Name | Type | Attribute | Description |
id | string | Trigger id. |
Example:
if (component.getTriggerDelta('pull') > 0) { entity.performAction('pull-rope'); }
public isAxisHold(id: string, treshold: number): boolean source
Tells if axis is currently hold.
Example:
if (component.isAxisHold('pos-x')) { entity.performAction('animate', 'walk'); }
public isAxisPressed(id: string, treshold: number): boolean source
Tells if axis is pressed in current frame.
Example:
if (component.isAxisPressed('bow')) { entity.performAction('aim'); }
public isAxisReleased(id: string, treshold: number): boolean source
Tells if axis is released in current frame.
Example:
if (component.isAxisReleased('bow')) { entity.performAction('fire'); }
public isTriggerHold(id: string, treshold: number): boolean source
Tells if trigger is currently hold.
Example:
if (component.isTriggerHold('swim')) { entity.performAction('swim'); }
public isTriggerPressed(id: string, treshold: number): boolean source
Tells if trigger is pressed in current frame.
Example:
if (component.isTriggerPressed('jump')) { entity.performAction('jump'); }
public isTriggerReleased(id: string, treshold: number): boolean source
Tells if trigger is released in current frame.
Example:
if (component.isTriggerReleased('fire')) { entity.performAction('fire'); }
public onGamepadConnected(gamepad: *) source
Override:
Script#onGamepadConnectedParams:
Name | Type | Attribute | Description |
gamepad | * |
public onGamepadDisconnected(gamepad: *) source
Override:
Script#onGamepadDisconnectedParams:
Name | Type | Attribute | Description |
gamepad | * |
public onGamepadProcess(gamepad: *) source
Override:
Script#onGamepadProcessParams:
Name | Type | Attribute | Description |
gamepad | * |
public onKeyDown(code: *) source
Override:
Script#onKeyDownParams:
Name | Type | Attribute | Description |
code | * |
public onMouseDown(unitVec: *, screenVec: *, button: *) source
Override:
Script#onMouseDownParams:
Name | Type | Attribute | Description |
unitVec | * | ||
screenVec | * | ||
button | * |
public onMouseMove(unitVec: *, screenVec: *) source
Override:
Script#onMouseMoveParams:
Name | Type | Attribute | Description |
unitVec | * | ||
screenVec | * |
public onMouseUp(unitVec: *, screenVec: *, button: *) source
Override:
Script#onMouseUpParams:
Name | Type | Attribute | Description |
unitVec | * | ||
screenVec | * | ||
button | * |
public onUpdate(deltaTime: *) source
Override:
Script#onUpdateParams:
Name | Type | Attribute | Description |
deltaTime | * |
public releaseGamepad() source
Release acquired gamepad.
Example:
if (gameOver) { component.releaseGamepad(); }
public setAcquiredGamepad(index: number) source
Manually acquire gamepad by it's index.
Params:
Name | Type | Attribute | Description |
index | number | Gamepad index. |
Example:
component.setAcquiredGamepad(0);
public setAxis(id: string, value: number) source
Set given axis value.
Example:
// reset axis to prevent further usage in this frame.
component.setAxis('pos-x', 0);
public setTrigger(id: string, value: number) source
Set given trigger value.
Example:
// reset trigger to prevent further usage in this frame.
component.setTrigger('pos-x', 0);
public setup(config: *) source
Setup axes and triggers.
Params:
Name | Type | Attribute | Description |
config | * | Configuration object. |
Example:
component.setup({ axes: { 'pos-x': { mouse: 'x' } }, triggers: { action: { key: 32 } } });