Class: InteractionManager

PIXI.InteractionManager

The interaction manager deals with mouse, touch and pointer events.

Any DisplayObject can be interactive if its interactive property is set to true.

This manager also supports multitouch.

An instance of this class is automatically created by default, and can be found at renderer.plugins.interaction

new PIXI.InteractionManager (renderer, options)

Name Type Attributes Default Description
renderer PIXI.CanvasRenderer | PIXI.Renderer

A reference to the current renderer

options object <optional>

The options for the manager.

options.autoPreventDefault boolean <optional>
true

Should the manager automatically prevent default browser actions.

options.interactionFrequency number <optional>
10

Maximum requency (ms) at pointer over/out states will be checked.

options.useSystemTicker number <optional>
true

Whether to add tickerUpdate to {@link PIXI.Ticker.system}.

Extends

Members

autoPreventDefault boolean

Should default browser actions automatically be prevented. Does not apply to pointer events for backwards compatibility preventDefault on pointer events stops mouse events from firing Thus, for every pointer event, there will always be either a mouse of touch event alongside it.

Default Value:
  • true

currentCursorMode string

The mode of the cursor that is being used. The value of this is a key from the cursorStyles dictionary.

cursorStyles Object<string, Object>

Dictionary of how different cursor modes are handled. Strings are handled as CSS cursor values, objects are handled as dictionaries of CSS values for interactionDOMElement, and functions are called instead of changing the CSS. Default CSS cursor values are provided for 'default' and 'pointer' modes.

eventData object

An event data object to handle all the event tracking/dispatching

interactionFrequency number

Maximum requency in milliseconds at which pointer over/out states will be checked by tickerUpdate.

Default Value:
  • 10

The mouse data

moveWhenInside boolean

This property determines if mousemove and touchmove events are fired only when the cursor is over the object. Setting to true will make things work more in line with how the DOM version works. Setting to false can make things easier for things like dragging It is currently set to false as this is how PixiJS used to work. This will be set to true in future versions of pixi.

Default Value:
  • false

The renderer this interaction manager works for.

resolution number

The current resolution / device pixel ratio.

Default Value:
  • 1

supportsPointerEvents boolean

Does the device support pointer events https://www.w3.org/Submission/pointer-events/

supportsTouchEvents boolean

Does the device support touch events https://www.w3.org/TR/touch-events/

useSystemTicker boolean

Should the InteractionManager automatically add tickerUpdate to {@link PIXI.Ticker.system}.

Default Value:
  • true

eventsAdded boolean protected

Have events been attached to the dom element?

interactionDOMElement HTMLElement protected

The DOM element to bind to.

lastObjectRendered PIXI.DisplayObject protected

Last rendered object or temp object

mouseOverRenderer boolean protected

Is the mouse hovering over the renderer? If working in worker mouse considered to be over renderer by default.

tickerAdded boolean protected

Has the system ticker been added?

Methods

destroy () void

Destroys the interaction manager

hitTest (globalPoint, root) PIXI.DisplayObject

Hit tests a point against the display tree, returning the first interactive object that is hit.

Name Type Attributes Description
globalPoint PIXI.Point

A point to hit test with, in global space.

root PIXI.Container <optional>

The root display object to start from. If omitted, defaults to the last rendered root of the associated renderer.

Returns:
Type Description
PIXI.DisplayObject The hit display object, if any.

mapPositionToPoint (point, x, y) void

Maps x and y coords from a DOM object and maps them correctly to the PixiJS view. The resulting value is stored in the point. This takes into account the fact that the DOM element could be scaled and positioned anywhere on the screen.

Name Type Description
point PIXI.IPointData

the point that the result will be stored in

x number

the x coord of the position to map

y number

the y coord of the position to map

setCursorMode (mode) void

Sets the current cursor mode, handling any callbacks or CSS style changes.

Name Type Description
mode string

cursor mode, a key from the cursorStyles dictionary

setTargetElement (element, resolution) void

Sets the DOM element which will receive mouse/touch events. This is useful for when you have other DOM elements on top of the renderers Canvas element. With this you'll be bale to delegate another DOM element to receive those events.

Name Type Attributes Default Description
element HTMLElement

the DOM element which will receive mouse and touch events.

resolution number <optional>
1

The resolution / device pixel ratio of the new element (relative to the canvas).

tickerUpdate (deltaTime) void

Updates the state of interactive objects if at least interactionFrequency milliseconds have passed since the last invocation.

Invoked by a throttled ticker update from PIXI.Ticker.system.

Name Type Description
deltaTime number

time delta since the last call

update () void

Updates the state of interactive objects.

processInteractive (interactionEvent, displayObject, func, hitTest) void protected

This function is provides a neat way of crawling through the scene graph and running a specified function on all interactive objects it finds. It will also take care of hit testing the interactive objects and passes the hit across in the function.

Name Type Attributes Description
interactionEvent PIXI.InteractionEvent

event containing the point that is tested for collision

displayObject PIXI.Container | PIXI.Sprite | PIXI.TilingSprite

the displayObject that will be hit test (recursively crawls its children)

func Function <optional>

the function that will be called on each interactive object. The interactionEvent, displayObject and hit will be passed to the function

hitTest boolean <optional>

indicates whether we want to calculate hits or just iterate through all interactive objects

Events

Fired when a pointer device button (usually a mouse left-button) is pressed and released on the display object.

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a pointer device button (usually a mouse left-button) is pressed on the display object.

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a pointer device (usually a mouse) is moved while over the display object

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a pointer device (usually a mouse) is moved off the display object

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a pointer device (usually a mouse) is moved onto the display object

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a pointer device button (usually a mouse left-button) is released over the display object.

Name Type Description
event PIXI.InteractionEvent

Interaction event

mouseupoutside

Fired when a pointer device button (usually a mouse left-button) is released outside the display object that initially registered a mousedown.

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when the operating system cancels a pointer event

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a pointer device button is pressed on the display object.

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a pointer device is moved while over the display object

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a pointer device is moved off the display object

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a pointer device is moved onto the display object

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a pointer device button is pressed and released on the display object.

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a pointer device button is released over the display object. Not always fired when some buttons are held down while others are released. In those cases, use mousedown and [mouseup]{@link PIXI.InteractionManager#event:mouseup} instead.

Name Type Description
event PIXI.InteractionEvent

Interaction event

pointerupoutside

Fired when a pointer device button is released outside the display object that initially registered a pointerdown.

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a pointer device secondary button (usually a mouse right-button) is pressed and released on the display object.

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a pointer device secondary button (usually a mouse right-button) is pressed on the display object.

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a pointer device secondary button (usually a mouse right-button) is released over the display object.

Name Type Description
event PIXI.InteractionEvent

Interaction event

rightupoutside

Fired when a pointer device secondary button (usually a mouse right-button) is released outside the display object that initially registered a rightdown.

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a touch point is placed and removed from the display object.

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when the operating system cancels a touch

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a touch point is removed from the display object.

Name Type Description
event PIXI.InteractionEvent

Interaction event

touchendoutside

Fired when a touch point is removed outside of the display object that initially registered a touchstart.

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a touch point is moved along the display object.

Name Type Description
event PIXI.InteractionEvent

Interaction event

Fired when a touch point is placed on the display object.

Name Type Description
event PIXI.InteractionEvent

Interaction event