Class CvsJoystick

This class simulates a multi-mode joystick. Each of the three possible modes apply different constraints to the range of movement allowed they are -.

'X0' : can move in any direction (360°).
'X4' : constrained to the 4 main compass directions (N, E, S, W).
'X8' : constrained to the 8 main compass directions (N, NE, E, SE, S, SW, W, NW).

To handle events use the setAction method to specify the action-method that will be used to process action-info objects created when the joystick is moved.

The action-info object has several very useful fields dthat describes the state of the joystick, they include -

  • dir
  • An integer that indicates the direction the stick is pushed. The values returned depend on the current mode -

    Direction values for X4 and X8 modes
         5   6   7
          \  |  /
           \ | /
       4 --- Z --- 0       Z is the dead zone.
           / | \
          /  |  \          If control is in mode 'X0' or the joystick
         3   2   1         position is in the dead zone the the value is -1
    

    'X0' : always -1
    'X4' : 0, 2, 4 or 6
    'X8' : 0, 1, 2, 3, 4, 5, 6 or 7

  • dead
  • If the stick is in the dead zone which surrounds the stick's rest state then this value will be true.

  • mag : has a value in range ≥ 0 and ≤ 1 representing the distance the stick has been pushed.
  • angle : has a value in range ≥ 0 and < 2π representing the angle the stick makes to the poistive x axis in the clockwise direction. In modes X4 and X8 the angles will be constrained to the permitted directions.
  • final : has the value false if the stick is still being moved and false if the stick has been released.

When the joystick is released it will return back to its rest state i.e. centered.

Since

1.1.0

Hierarchy

Properties

action: Function = ...

The event handler for this control. Although it is permitted to set this property directly it is recommended that the setAction(...) method is used to define the event handler actions.

Methods

  • Add a child to this control using its relative position [rx, ry]. If rx and ry are not provided then it uses the values set in the child.

    Returns

    this control

    Parameters

    • c: string | CvsBaseControl

      is the actual control or its name

    • Optional rx: number
    • Optional ry: number

    Returns any

  • Set or get the corner radii used for this control

    Returns

    an array with the 4 corner radii

    Parameters

    • c: number[]

      an array of 4 corner radii

    Returns number[] | CvsBaseControl

  • Use enable() and disable() to enable and disable it.

    Returns

    true if the control is enabled else false

    Returns boolean

  • Returns

    true if this control is visible

    Since

    0.9.3

    Returns boolean

  • Returns

    the unique identier for this control

    Returns string

  • Adds this control to another control which becomes its parent

    Returns

    this control

    Parameters

    • p: string | CvsBaseControl

      is the parental control or its name

    • Optional rx: number

      x position relative to parent

    • Optional ry: number

      y position relative to parent

    Returns CvsBaseControl

  • Sets or gets the color scheme used by this control.

    Returns

    this control or the control's color scheme

    Parameters

    • Optional id: string

      the color scheme id e.g. 'blue'

    • Optional cascade: boolean

      if true propogate scheme to all child controls.

    Returns any

  • This sets the event handler to be used when this control fires an event. The parameter can take three forms:

    1. Arrow function definition
    2. Anonymous function definition
    3. Named function declaration

    Returns

    this control

    Parameters

    • event_handler: Function

      the function to handle this controls event

    Returns CvsJoystick

  • Shrink the control to fit contents.

    To shrink on one dimension only pass either 'w' (width) or 'h' (height) to indicate which dimmension to shrink

    Returns

    this control

    Parameters

    • Optional dim: string

      the dimension to shrink

    Returns CvsBaseControl

  • Set the thumb size.

    Returns

    this control

    Parameters

    • ts: number

      the diameter of the thumb

    Returns CvsJoystick

  • Create a tooltip for this control

    Returns

    this control

    Parameters

    • tiptext: string

      the text to appear in the tooltip

    • duration: number = 1600

      how long the tip remains visible (milliseconds)

    Returns CvsJoystick

Generated using TypeDoc