NGL@1.0.0-beta.7 Home Manual Reference Source Gallery
import KeyControls from 'ngl/src/controls/key-controls.js'
public class | source

KeyControls

Mouse controls

Constructor Summary

Public Constructor
public

constructor(stage: Stage, params: Object)

Member Summary

Public Members
public
public

Flag to disable all actions

public

Method Summary

Public Methods
public

add(char: Char, callback: Function): undefined

Add a key action triggered by pressing the given character.

public

Remove all key actions

public

Set key action preset

public

remove(char: Char, callback: Function): undefined

Remove a key action.

public

run()

Public Constructors

public constructor(stage: Stage, params: Object) source

Params:

NameTypeAttributeDescription
stage Stage

the stage object

params Object
  • optional

the parameters

params.preset String

one of "default"

params.disabled String

flag to disable all actions

Public Members

public actionList source

public disabled: Boolean source

Flag to disable all actions

public stage source

Public Methods

public add(char: Char, callback: Function): undefined source

Add a key action triggered by pressing the given character. The KeyActions class provides a number of static methods for use as callback functions.

Params:

NameTypeAttributeDescription
char Char

the key/character

callback Function

the callback function for the action

Return:

undefined

Example:

// call KeyActions.toggleRock when "k" is pressed
stage.keyControls.remove( "k", KeyActions.toggleRock );

public clear(): undefined source

Remove all key actions

Return:

undefined

public preset(name: String): undefined source

Set key action preset

Params:

NameTypeAttributeDescription
name String

one of "default"

Return:

undefined

public remove(char: Char, callback: Function): undefined source

Remove a key action. When the callback function is given, only actions that call that function are removed.

Params:

NameTypeAttributeDescription
char Char

the key/character

callback Function
  • optional

the callback function for the action

Return:

undefined

Example:

// remove all actions triggered by pressing "k"
stage.keyControls.remove( "k" );
// remove action `toggleRock` triggered by pressing "k"
stage.keyControls.remove( "k", toggleRock );

public run() source