Reference Source
import {Controller} from 'mobile-handler/src/controller.mjs'
public class | source

Controller

When using a controller that is of the traversal type, or the static type a zone is REQUIRED. Only two controllers of traversal or static or one of each can be used at a time. These controllers have to have opposing zones. Left | Right Traversal: spawns at the touch position and when dragged, follows the finger across the screen Static: spawns at the touch position, cannot move from that location, just updates the joystick and will clamp at its limit Stationary: cannot move from it's position at all, will just update the joystick and clamp it at its limit, can be pressed from anywhere on screen.

Static Member Summary

Static Private Members
private static

The maximum layer

Constructor Summary

Private Constructor
private

Member Summary

Public Members
public

version: *

The version of the module.

Private Members
private

Whether this controller is active

private

Whether this controller is active in zone.

private

The fingerID that is controlling the joystick.

private

The joyring element of this controller.

private

The joystick element of this controller.

private

The locked dimension of the joystick.

private

Event function for when the joystick is moved.

private

Event function for when the joystick is released.

private

The options of this controller.

private

tween: Tween

A reference to the tween instance this controller uses to tween the alpha when it becomes inactive.

private

The zone the joystick will occupy.

Method Summary

Public Methods
public

build(pOptions: Object)

Builds this controller with the options that were passed in.

public

Returns the components that make up this controller.

public

getType(): *

Returns the type of this controller.

public

hide()

Hides this controller

public

lock(pDimension: string)

Locks a joystick from moving in a certain dimension or both

public

show()

Shows this controller

public

unlock(pDimension: string)

Unlocks the joystick from being locked in the passed dimension.

Private Methods
private

Tweens the controller to it's inactive alpha preset, or from it's inactive value preset to full alpha.

private

release(pForce: boolean)

API called when this joystick is released

private

reset(pSoft: *)

Resets the joystick to default.

private

setup()

private

update(pX: number, pY: number, pTouchStart: boolean)

Updates the controllers position with the latest information from touch events

Static Private Members

private static MAX_LAYER: number source

The maximum layer

Private Constructors

private constructor() source

Public Members

public version: * source

The version of the module.

Private Members

private active: boolean source

Whether this controller is active

private activeInZone: boolean source

Whether this controller is active in zone. e.g the controller is zoned to the left, and the user taps on the left side of the screen.

private controllingFinger: number source

The fingerID that is controlling the joystick.

private joyring: Object source

The joyring element of this controller.

private joystick: Object source

The joystick element of this controller.

private lockedDimension: string source

The locked dimension of the joystick. both | vertical | horizontal. This is used to lock the joystick from moving in certain dimensions. If this joystick's type is traversal it cannot be locked.

private onMove: Function source

Event function for when the joystick is moved.

private onRelease: Function source

Event function for when the joystick is released.

private options: Object source

The options of this controller.

Properties:

NameTypeAttributeDescription
options Object

The options of this controller.

options.type string

The way this controller will behave. stationary | traversal | static.

options.size number

The width/height of the joystick. The width & height of the joystick should be the same.

options.position Object

The initial position of the joystick.

options.position.x string

The initial x position of the joystick.

options.position.y string

The initial y position of the joystick.

options.lockedDimension string

The locked dimension of the joystick. both | vertical | horizontal. This is used to lock the joystick from moving in certain dimensions. If this joystick's type is traversal it cannot be locked.

options.zone string

The zone the joystick will occupy. If there is already a controller of the traversal or static type, then you must use a zone. If there is only one controller no zone is needed. left | right This will give each controller equal space on the left | right sides of the screen.

options.inactiveAlpha number

The alpha value the joystick will be when it is considered to be inactive.

options.transitionTime number

How long it takes in ms to transition to the inactiveAlpha value.

options.scale number

The scale you want the joystick controller to be.

options.plane number

The plane of the joystick controller.

options.layer number

The layer of the joystick controller.

options.atlasName string

The atlasName of the joystick.

options.joystickIconName string

The iconName of the joystick.

options.joyringIconName string

The iconName of the joyring.

options.callback Object

An object holding options callbacks to attach to events the joystick emits.

options.callback.onTouchBegin Function

Callback to be called when the joystick is touched after being released.

options.callback.onRelease Function

Callback to be called when the joystick is released and no longer held.

options.callback.onMove Function

Callback to be called when the joystick is moved.

private tween: Tween source

A reference to the tween instance this controller uses to tween the alpha when it becomes inactive. This reference is so that developers can pause this tween and resume it when needed. Calling this.tween.pause() and this.tween.resume() for instance when pausing and unpausing the game.

private zone: string source

The zone the joystick will occupy. If there is already a controller of the traversal or static type, then you must use a zone. If there is only one controller no zone is needed. left | right This will give each controller equal space on the left | right sides of the screen.

Public Methods

public build(pOptions: Object) source

Builds this controller with the options that were passed in.

Params:

NameTypeAttributeDescription
pOptions Object

The options of this controller.

pOptions.type string

The way this controller will behave. stationary | traversal | static.

pOptions.size number

The width/height of the joystick. The width & height of the joystick should be the same. The inner ring will be 50% of this size.

pOptions.position Object

The initial position of the joystick.

pOptions.position.x string

The initial x position of the joystick.

pOptions.position.y string

The initial y position of the joystick.

pOptions.lockedDimension string

The locked dimension of the joystick. both | vertical | horizontal. This is used to lock the joystick from moving in certain dimensions. If this joystick's type is traversal it cannot be locked.

pOptions.zone string

The zone the joystick will occupy. If there is already a controller of the traversal or static type, then you must use a zone. If there is only one controller no zone is needed. left | right This will give each controller equal space on the left / right sides of the screen.

pOptions.inactiveAlpha number

The alpha value the joystick will be when it is considered to be inactive.

pOptions.transitionTime number

How long it takes in ms to transition to the inactiveAlpha value.

pOptions.scale number

The scale you want the joystick controller to be.

pOptions.plane number

The plane of the joystick controller.

pOptions.layer number

The layer of the joystick controller.

pOptions.atlasName string

The atlasName of the joystick.

pOptions.joystickIconName string

The iconName of the joystick.

pOptions.joyringIconName string

The iconName of the joyring.

pOptions.callback Object

An object holding options callbacks to attach to events the joystick emits.

pOptions.callback.onTouchBegin Function

Callback to be called when the joystick is touched after being released.

pOptions.callback.onRelease Function

Callback to be called when the joystick is released and no longer held.

pOptions.callback.onMove Function

Callback to be called when the joystick is moved.

public getComponents(): Object source

Returns the components that make up this controller. Which are the joystick element, and the joyring element.

Return:

Object

An object containing references to the joytick and the joyring that makeup this controller.

public getType(): * source

Returns the type of this controller.

Return:

*

Returns the type of this controller.

public hide() source

Hides this controller

public lock(pDimension: string) source

Locks a joystick from moving in a certain dimension or both

Params:

NameTypeAttributeDescription
pDimension string

The dimension to lock. both | vertical | horizontal

public show() source

Shows this controller

public unlock(pDimension: string) source

Unlocks the joystick from being locked in the passed dimension.

Params:

NameTypeAttributeDescription
pDimension string

The dimension to unlock. both | vertical | horizontal

Private Methods

private handleTransition(pFade: boolean) source

Tweens the controller to it's inactive alpha preset, or from it's inactive value preset to full alpha.

Params:

NameTypeAttributeDescription
pFade boolean

Whether to fade the joystick to it's inactive alpha preset

private release(pForce: boolean) source

API called when this joystick is released

Params:

NameTypeAttributeDescription
pForce boolean

If this was a forced release. Called progamatically.

private reset(pSoft: *) source

Resets the joystick to default.

Params:

NameTypeAttributeDescription
pSoft *

Softly resets the joystick in the event it is hidden

private setup() source

private update(pX: number, pY: number, pTouchStart: boolean) source

Updates the controllers position with the latest information from touch events

Params:

NameTypeAttributeDescription
pX number

The x position on the screen where the user tapped.

pY number

The y position on the screen where the user tapped.

pTouchStart boolean

If this was the first time the joystick was touched.