Class: phaserControls

phaserControls(scene, pluginManager)

GitHub: https://github.com/retroVX/phaser3-controls-plugin
A simple plugin to assist with creating control schemes with keyboard inputs for Phaser (3)

Constructor

new phaserControls(scene, pluginManager)

Parameters:
Name Type Description
scene Phaser.Scene The Scene the phaserControls will be created in (this)
pluginManager Phaser.pluginManager Phaser plugin manager
Author:
  • Conor Irwin <conorirwin.co.uk>
Source:

Extends

  • Phaser.Plugins.ScenePlugin

Members

(static) inputArray

Holds all inputs recorded with phaserControls.recordKeys
Since:
  • 1.5.0
Source:

(static) keys :Object

Stores the keyboard keys that have been created from a control scheme
Type:
  • Object
Since:
  • 1.0.0
Source:

(static) scene :Object

Get 'this' from scene
Type:
  • Object
Since:
  • 1.0.0
Source:

(static) schemes :Array

Holds all the control schemes in an array
Type:
  • Array
Since:
  • 1.0.0
Source:

Methods

(static) add(config) → {function}

Add new control scheme and switch to the new scheme if it's set to 'active'
Parameters:
Name Type Description
config object A new scheme config to be added to the schemes array
Since:
  • 1.0.0
Source:
Returns:
Type
function

(static) addMultiple(array) → {function}

Adds an array of multiple control scheme objects into the schemes array
Useful if saving the controls with localStorage
Parameters:
Name Type Description
array Array An array of control scheme objects
Since:
  • 1.0.0
Source:
Returns:
Type
function

(static) createCombo(scheme) → {function|Object}

Create a key combo Add a combo scheme globally or only when using a specific control scheme
Parameters:
Name Type Description
scheme Object combo scheme config to pass into the keyboard manager
Since:
  • 1.3.0
Source:
Returns:
  • Type
    function
  • returns the combo object so you can edit/delete when needed
    Type
    Object

(static) createCursorKeys(activeopt, addopt, data, onActiveFunc) → {function}

Create default cursor keys. The difference between this.input.keyboard.createCursorKeys(); and phaserControls.createCursorKeys(); is that the phaserControls will be added to the control scheme array with other created control schemes.
Parameters:
Name Type Attributes Default Description
active boolean <optional>
false If the cursor keys should be used, overiding current scheme
add boolean <optional>
true add the default cursor keys to the schemes list
data object optional data to pass into the control scheme
onActiveFunc function optional function to call whenever this control scheme is set to active
Since:
  • 1.0.0
Source:
Returns:
Type
function

(static) createKonamiCode(onMatch) → {function|Object}

Create the Konami Code (up,up,down,down,left,right,left,right,b,a)
Parameters:
Name Type Description
onMatch function function to call when konami code has been entered
Since:
  • 1.3.0
Source:
Returns:
  • Type
    function
  • returns the konami combo object
    Type
    Object

(static) createWasdKeys(activeopt, addopt, data, onActiveFunc) → {function}

Create default wasd keys. The same approach as phaserControls.createCursorKeys but using WASD instead.
Parameters:
Name Type Attributes Default Description
active boolean <optional>
false If the wasd keys should be used, overiding current scheme
add boolean <optional>
true add the default wasd keys to the schemes list
data object optional data to pass into the control scheme
onActiveFunc function optional function to call whenever this control scheme is set to active
Since:
  • 1.0.0
Source:
Returns:
Type
function

(static) debugText(x, y, fontsize, color) → {function}

Debug text displaying current control scheme thats being used. Click on the text to move onto the next control scheme and select it.
Parameters:
Name Type Description
x number x coordinate for text display on canvas
y number y coordinate for text display on canvas
fontsize number Fontsize to display the text at.
color string font color.
Since:
  • 1.0.0
Source:
Returns:
Type
function

(static) delete(scheme, destroyopt) → {function}

Delete scheme from the schemes array and removes key and key captures
Parameters:
Name Type Attributes Default Description
scheme string | object The scheme name to find and delete
destroy boolean <optional>
true Removes keys and captures used by scheme (phaser version >= 3.16)
Since:
  • 1.0.0
Source:
Returns:
Type
function

(static) disableKeys() → {function}

Helper function to disable all the keys for the active control scheme
Since:
  • 1.5.0
Source:
Returns:
Type
function

(static) edit(scheme, config) → {function}

Edit control scheme. This is used if you need to edit a control scheme on the front end
Parameters:
Name Type Description
scheme string | object The scheme name to find and edit
config Object config to edit
Since:
  • 1.0.0
Source:
Returns:
Type
function

(static) enableKeys() → {function}

Helper function to enable all the keys for the active control scheme
Since:
  • 1.5.0
Source:
Returns:
Type
function

(static) get(name, activeopt) → {function|Object}

Returns the control scheme object that matches the control scheme name
Parameters:
Name Type Attributes Default Description
name string The name of the scheme to get and return as object
active boolean <optional>
false if the scheme should be used, overiding current scheme
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • The control scheme object
    Type
    Object

(static) getActive(nameopt) → {function|Object|string}

Returns the active control scheme object or name string
Parameters:
Name Type Attributes Default Description
name boolean <optional>
false If true returns only the schemes name
Since:
  • 1.0.0
Source:
Returns:
  • Type
    function
  • The control scheme object or string
    Type
    Object | string

(static) getAll() → {function|Array}

returns an array with all the control schemes
Since:
  • 1.1.0
Source:
Returns:
  • Type
    function
  • The array containing the control schemes
    Type
    Array

(static) keyCodeToKey(keyCode) → {function|string|array}

Helper function to convert a keyCode either from phaser keyboard or from window event to the phaser key string
Parameters:
Name Type Description
keyCode number | array the keyCode to convert or an array of keyCodes to convert
Since:
  • 1.5.0
Source:
Returns:
  • Type
    function
  • Returns the key name or an array of key names
    Type
    string | array

(static) recordKeys() → {function|array}

record which key was pressed down, for how long and the timestamp when the key was down
Since:
  • 1.5.0
Source:
Returns:
  • Type
    function
  • returns the array holding the input objects
    Type
    array

(static) setActive(scheme) → {function}

Select control scheme while turning off the currently used scheme
Parameters:
Name Type Description
scheme string | Object the 'name' or object of a scheme to be selected
Since:
  • 1.0.0
Source:
Returns:
Type
function

(static) switch(scheme) → {function}

Switch from one control scheme to another Alternative way of setActive();
Parameters:
Name Type Description
scheme string | object the control scheme to switch to
Since:
  • 1.1.0
Source:
Returns:
Type
function