duckengine
Version:
A 2D Game Engine for the web.
94 lines (93 loc) • 3.04 kB
TypeScript
import { Duck } from '../..';
import EventEmitter from '../events/eventEmitter';
import Game from '../game';
import Scene from '../scene';
import Key from './models/key';
/**
* @class KeyboardInput
* @classdesc Creates a DuckEngine KeyboardInput
* @description The KeyboardInput Class. Use the Keyboard as input
* @since 2.0.0
*/
export default class KeyboardInput {
/**
* @memberof KeyboardInput
* @description Game instance
* @type Game
* @since 2.0.0
*/
game: Game;
/**
* @memberof KeyboardInput
* @description Scene instance
* @type Scene
* @since 2.0.0
*/
scene: Scene;
/**
* @memberof KeyboardInput
* @description The EventEmitter used to emit for Key events
* @type EventEmitter
* @since 2.0.0
*/
eventEmitter: EventEmitter;
/**
* @memberof KeyboardInput
* @description All of the Keys added to the KeyboardInput
* @type { [key: string]: Key }
* @since 2.0.0
*/
keys: {
[key: string]: Key;
};
/**
* @memberof KeyboardInput
* @description Creates a KeyboardInput instance
* @param {Game} game Game instance
* @param {Scene} scene Scene instance
* @since 2.0.0
*/
constructor(game: Game, scene: Scene);
/**
* @memberof KeyboardInput
* @description Adds a Key to the KeyboardInput
* @param {number} keyCode The Key keyCode
* @param {string} descriptor The Key descriptor, used to set the value to KeyboardInput.keys
* @param { (e:KeyboardEvent) => any } [keyDown] Key Down callback
* @param { (e:KeyboardEvent) => any } [keyUp] Key Up callback
* @param { (e:KeyboardEvent) => any } [keyJustPressed] Key Just Pressed callback
* @param { (e:KeyboardEvent) => any } [keyState] Key State callback
* @since 2.0.0
*/
addKey(keyCode: number, descriptor: string, keyDown?: (e: KeyboardEvent) => any, keyUp?: (e: KeyboardEvent) => any, keyJustPressed?: (e: KeyboardEvent) => any, keyState?: (e: KeyboardEvent, state: boolean) => any): Key;
/**
* @memberof KeyboardInput
* @description Adds a Key to the KeyboardInput
* @param {Duck.Types.KeyboardInput.KeyBase[]} keys An array of base key configurations to create Keys from
* @since 2.0.0
*/
addKeys(keys: Duck.Types.KeyboardInput.KeyBase[]): void;
/**
* @memberof KeyboardInput
* @description Removes a Key from the KeyboardInput
* @param {string} descriptor Key descriptor
* @since 2.0.0
*/
removeKey(descriptor: string): void;
/**
* @memberof KeyboardInput
* @description Adds an onInput event listener to all keys
* @param {(key:Key,e:KeyboardEvent)=>any} cb
* @since 2.0.0
*/
onInput(cb: (key: Key, e: KeyboardEvent) => any): void;
/**
* @memberof KeyboardInput
* @description Returns KeyboardInput.keys
* @returns {{ [key: string]: Key }}
* @since 2.0.0
*/
get inputs(): {
[key: string]: Key;
};
}