Class: Controller2D

Controller2D

Controller for handling 2D position updates based on pan and tap events. Extends the base Controller to track a 2D position (x, y) of the device pointer.

Supports two coordinate systems:

  • Absolute: Coordinates mapped to [-1, 1] with origin at bottom-left of canvas
  • Relative: Coordinates based on distance from initial pan position, scaled by speed

new Controller2D(callback [, options])

Creates a new Controller2D instance.

Parameters:
Name Type Argument Description
callback updatePosition

Function called when position is updated

options Object <optional>

Configuration options

Properties
Name Type Argument Default Description
relative boolean <optional>
false

Whether to use relative coordinate system

speed number <optional>
2.0

Scaling factor for relative coordinates

box BoundingBox <optional>

Bounding box for coordinate constraints

onPanStart updatePosition <optional>

Callback for pan start event

onPanEnd updatePosition <optional>

Callback for pan end event

active boolean <optional>
true

Whether the controller is active

activeModifiers Array.<number> <optional>
[0]

Array of active modifier states

Source:

Extends

Methods


<abstract> fingerDoubleTap(e)

Called for quick double mouse press or double finger touch.

Parameters:
Name Type Description
e Event

The double tap event

Inherited From:
Overrides:
Source:

fingerSingleTap(e)

Handles single tap/click events. Only processes events in absolute coordinate mode.

Parameters:
Name Type Description
e MouseEvent | TouchEvent

Tap event

Inherited From:
Overrides:
Source:

modifierState(e)

Gets the modifier state from an event.

Parameters:
Name Type Description
e Event

The event to check

Inherited From:
Overrides:
Source:
Returns:

Modifier state bitmask where:

  • 0 = No modifiers
  • 1 = Ctrl key
  • 2 = Shift key
  • 4 = Alt key Multiple modifiers combine their values (e.g., Ctrl+Shift = 3)
Type
number

<abstract> mouseWheel(e)

Called when user rotates mouse wheel.

Parameters:
Name Type Description
e WheelEvent

The wheel event

Inherited From:
Overrides:
Source:

panEnd(e)

Handles end of pan gesture.

Parameters:
Name Type Description
e MouseEvent | TouchEvent

Pan end event

Inherited From:
Overrides:
Source:
Returns:

False if not currently panning

Type
boolean

panMove(e)

Handles pan movement.

Parameters:
Name Type Description
e MouseEvent | TouchEvent

Pan move event

Inherited From:
Overrides:
Source:
Returns:

False if not currently panning

Type
boolean

panStart(e)

Handles start of pan gesture.

Parameters:
Name Type Description
e MouseEvent | TouchEvent

Pan start event

Inherited From:
Overrides:
Source:

<abstract> pinchEnd(e1, e2)

Called when pinch ends (finger lift).

Parameters:
Name Type Description
e1 Event

First finger event

e2 Event

Second finger event

Inherited From:
Overrides:
Source:

<abstract> pinchMove(e1, e2)

Called continuously during pinching.

Parameters:
Name Type Description
e1 Event

First finger event

e2 Event

Second finger event

Inherited From:
Overrides:
Source:

<abstract> pinchStart(e1, e2)

Called when user starts a two-finger pinch. Call e1.preventDefault() to capture the event.

Parameters:
Name Type Description
e1 Event

First finger event

e2 Event

Second finger event

Inherited From:
Overrides:
Source:

setPosition(x, y)

Updates the stored position for relative coordinate system. This is a convenience method typically used within callbacks.

Parameters:
Name Type Description
x number

New X coordinate in range [-1, 1]

y number

New Y coordinate in range [-1, 1]

Source: