import Touch from "./Touch"; import EventDispatcher from "./EventDispatcher"; import Event from "./Event"; import DisplayObject from "../display/DisplayObject"; import Vector from "openfl/Vector"; declare namespace starling.events { /** * A TouchEvent is triggered either by touch or mouse input. * * * *

In Starling, both touch events and mouse events are handled through the same class: * * TouchEvent. To process user input from a touch screen or the mouse, you have to register * * an event listener for events of the type TouchEvent.TOUCH. This is the only * * event type you need to handle; the long list of mouse event types as they are used in * * conventional Flash are mapped to so-called "TouchPhases" instead.

* * * *

The difference between mouse input and touch input is that

* * * * * * * * Which objects receive touch events? * * * *

In Starling, any display object receives touch events, as long as the * * touchable property of the object and its parents is enabled. There * * is no "InteractiveObject" class in Starling.

* * * * How to work with individual touches * * * *

The event contains a list of all touches that are currently present. Each individual * * touch is stored in an object of type "Touch". Since you are normally only interested in * * the touches that occurred on top of certain objects, you can query the event for touches * * with a specific target:

* * * * var touches:Vector.<Touch> = touchEvent.getTouches(this); * * * *

This will return all touches of "this" or one of its children. When you are not using * * multitouch, you can also access the touch object directly, like this:

* * * * var touch:Touch = touchEvent.getTouch(this); * * * * @see Touch * * @see TouchPhase * */ export class TouchEvent extends Event { /** * Creates a new TouchEvent instance. */ constructor(type: string, touches?: Vector, shiftKey?: boolean, ctrlKey?: boolean, bubbles?: boolean); /** * Event type for touch or mouse input. */ static readonly TOUCH = "touch"; /** * Returns a list of touches that originated over a certain target. If you pass an * * out-vector, the touches will be added to this vector instead of creating * * a new object. */ getTouches(target: DisplayObject, phase?: string, out?: Vector): Vector; /** * Returns a touch that originated over a certain target. * * * * @param target The object that was touched; may also be a parent of the actual * * touch-target. * * @param phase The phase the touch must be in, or null if you don't care. * * @param id The ID of the requested touch, or -1 if you don't care. * */ getTouch(target: DisplayObject, phase?: string, id?: number): Touch; /** * Indicates if a target is currently being touched or hovered over. */ interactsWith(target: DisplayObject): boolean; /** * @private * * Dispatches the event along a custom bubble chain. During the lifetime of the event, * * each object is visited only once. */ dispatch(chain: Vector): void; /** * The time the event occurred (in seconds since application launch). */ get timestamp(): number; /** * All touches that are currently available. */ get touches(): Vector; /** * Indicates if the shift key was pressed when the event occurred. */ get shiftKey(): boolean; /** * Indicates if the ctrl key was pressed when the event occurred. (Mac OS: Cmd or Ctrl) */ get ctrlKey(): boolean; } } export default starling.events.TouchEvent;