Skip to content

MultiListener

Overview

MultiListener is responsible for monitoring the mouse, touch, and other presses on the screen and determines the operations to apply to a target Node from this input. Single touch dragging on the screen will initiate panning. Multi-touch gestures will initiate scaling, translation, and potentially rotation depending on the gesture.

MultiListener will keep track of all "background" presses on the screen. When certain conditions are met, the "background" presses become active and attached listeners may be interrupted so that the MultiListener gestures take precedence. MultiListener uses the Intent feature of Pointer, so that the default behavior of this listener can be prevented if necessary. Generally, you would use Pointer.reserveForDrag() to indicate that your Node is intended for other input that should not be interrupted by this listener.

For example usage, see scenery/examples/input.html. A typical "simple" MultiListener usage would be something like:

display.addInputListener( new PressListener( targetNode ) );

@author Jonathan Olson <jonathan.olson@colorado.edu> @author Jesse Greenberg

Class MultiListener

import { MultiListener } from 'scenerystack/scenery';

Constructor

new MultiListener( targetNode : Node, providedOptions? : MultiListenerOptions )

Instance Methods

addPress( press : MultiListenerPress )

(protected)

Add a Press to this listener when a new Pointer is down.

movePress( press : MultiListenerPress )

(protected)

Reposition in response to movement of any Presses.

removePress( press : MultiListenerPress )

(protected)

Remove a Press from this listener.

reposition()

(protected)

Reposition the target Node (including all apsects of transformation) of this listener's target Node.

recomputeLocals()

(protected)

Recompute the local points of the Presses for this listener, relative to the target Node.

interrupt()

Interrupt this listener.

computeTranslationMatrix() : Matrix3

Compute a translation matrix from multiple presses. Usually multiple presses will have some scale or rotation as well, but this is to be used if rotation and scale are not enabled for this listener.

limitScale( scale : number ) : number

(protected)

Limit the provided scale by constraints of this MultiListener.

getCurrentScale() : number

Get the current scale on the target Node, assumes that there is isometric scaling in both x and y.

resetTransform()

Reset transform on the target Node.

Instance Properties

matrixProperty : Property<Matrix3>

(readonly)

{Property.<Matrix3>} - The matrix applied to the targetNode in response to various input for the MultiListener

Type MultiListenerOptions

import type { MultiListenerOptions } from 'scenerystack/scenery';
  • mouseButton?: number
    {number} - Restricts input to the specified mouse button (but allows any touch). Only one mouse button is allowed at a time. The button numbers are defined in https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button, where typically: 0: Left mouse button 1: Middle mouse button (or wheel press) 2: Right mouse button 3+: other specific numbered buttons that are more rare
  • pressCursor?: string
    {string} - Sets the Pointer cursor to this cursor when the listener is "pressed".
  • allowScale?: boolean
    {boolean} - If true, the listener will scale the targetNode from input
  • allowRotation?: boolean
    {boolean} - If true, the listener will rotate the targetNode from input
  • allowMultitouchInterruption?: boolean
    {boolean} - if true, multitouch will interrupt any active pointer listeners and initiate translation and scale from multitouch gestures
  • allowMoveInterruption?: boolean
    if true, a certain amount of movement in the global coordinate frame will interrupt any pointer listeners and initiate translation from the pointer, unless default behavior has been prevented by setting Intent on the Pointer.
  • minScale?: number
    magnitude limits for scaling in both x and y
  • maxScale?: number
  • & Pick<PhetioObjectOptions, "tandem">

Source Code

See the source for MultiListener.ts in the scenery repository.