Skip to content

SpriteEventDispatcher

Type class

An EventDispatcher for Sprite.

More info: Events

Sources

This information about SpriteEventDispatcher is provided for reference only and is not available through exported packages and thus should not be imported or used on its own.

Inheritance

SpriteEventDispatcher extends EventDispatcher.

SpriteEventDispatcher is not extended by any other symbol.

Properties

SpriteEventDispatcher does not have any properties.

Methods

constructor(sprite: Sprite)

Returns SpriteEventDispatcher

stopParentDispatch()

Returns void

Stops the event being handled from being dispatched on the element's parents. Call it in an event handler, e.g.:

element.events.on("pointerdown", function(ev) {
  // Do something here and prevent from "pointerdown" bubbling up
  // ...
  ev.target.events.stopParentDispatch();
});
element.events.on("pointerdown", function(ev) {
  // Do something here and prevent from "pointerdown" bubbling up
  // ...
  ev.target.events.stopParentDispatch();
});
17 inherited items
disable()

Returns voidInherited from EventDispatcher

Disable dispatching of events until re-enabled by enable().

disableType(type: Key,
amount: number
)

Returns voidInherited from EventDispatcher

Stops dispatching events of type, until enableType() is called or, if amount is set, for that many dispatches.

dispatch(type: Key,
event: T[""]
)

Returns voidInherited from EventDispatcher

Calls the listeners of type right away; debounced listeners are called after their delay. event must include type and target.

dispose()

Returns voidInherited from EventDispatcher

Disposes the dispatcher and all its listeners.

enable()

Returns voidInherited from EventDispatcher

Enable dispatching of events if they were previously disabled by disable().

enableType(type: Key)

Returns voidInherited from EventDispatcher

Enable dispatching particular event, if it was disabled before by disableType().

has(type: Key,
callback?: undefined | (this: C, event: T[""]) => void,
context?: C
)

Returns booleanInherited from EventDispatcher

Checks if there's already a listener with specific parameters. Listeners added with once() are not counted.

hasListeners()

Returns booleanInherited from EventDispatcher

Checks if the dispatcher has any listeners.

hasListenersByType(type: Key)

Returns booleanInherited from EventDispatcher

Checks if the dispatcher has listeners for type, counting the ones added with onAll().

isDisposed()

Returns booleanInherited from EventDispatcher

Returns true if the dispatcher has been disposed.

isEnabled(type: Key)

Returns booleanInherited from EventDispatcher

Checks if an event of type would reach a listener: events are enabled, the type is not disabled, and it has listeners.

off(type: Key,
callback?: undefined | (this: C, event: T[""]) => void,
context?: C
)

Returns voidInherited from EventDispatcher

Removes listeners added with on() or onDebounced() that match type, callback and context. Without callback, removes all of them for type and context. Listeners added with once() are not removed.

on(type: Key,
callback: (this: C | undefined, event: T[""]) => void,
context?: C,
shouldClone: boolean
)

Returns IDisposerInherited from EventDispatcher

Creates an event listener to be invoked on a specific event type.

button.events.on("click", (ev) => {
  console.log("Button clicked");
}, this);
button.events.on("click", function(ev) {
  console.log("Button clicked");
}, this);

The above logs every click on the button. To remove the listener, call dispose() on the returned object, or use off().

onAll(callback: (this: C, event: T[""]) => void,
context?: C,
shouldClone: boolean
)

Returns IDisposerInherited from EventDispatcher

Creates an event listener to be invoked on any event.

once(type: Key,
callback: (this: C | undefined, event: T[""]) => void,
context?: C,
shouldClone: boolean
)

Returns IDisposerInherited from EventDispatcher

Creates an event listener that is invoked only the first time the event happens, and is then disposed.

button.events.once("click", (ev) => {
  console.log("Button clicked");
}, this);
button.events.once("click", function(ev) {
  console.log("Button clicked");
}, this);

The above logs the first click on the button only. off() does not remove such a listener: call dispose() on the returned object instead.

onDebounced(type: Key,
callback: (this: C | undefined, event: T[""]) => void,
debounceDelay: number,
context?: C,
shouldClone: boolean
)

Returns IDisposerInherited from EventDispatcherSince 5.14.0

Creates a debounced event listener to be invoked on a specific event type.

button.events.onDebounced("click", (ev) => {
  console.log("Button clicked");
}, 500, this);
button.events.onDebounced("click", function(ev) {
  console.log("Button clicked");
}, 500, this);

The above logs once, 500 ms after the last of a series of clicks. Each new event restarts the delay, and callback gets the last one.

More info: Events: debounced events

removeType(type: Key)

Returns voidInherited from EventDispatcher

Removes all listeners of a particular event type.

Events

SpriteEventDispatcher does not have any events.