EventManager
APJS Script API reference for the EventManager namespace.
| Type | Name | Interface Description |
|---|---|---|
| Static Functions | createEvent(eventType: number | UserEventType): IEvent | • Function: Creates and returns a new event instance based on the provided event type. Parameters • Returns An IEvent object representing the created event. |
| Static Functions | defineUserEventType(eventName: number | string): UserEventType | • Function: Defines a user-defined event type. This method allows you to create and register a custom event type with a unique identifier, which can be used to trigger and handle events in your application. Parameters • Returns The newly defined or existing UserEventType associated with the provided identifier. |
| Static Functions | getGestureEmitter(): IEventEmitter | • Function: Retrieves the event emitter associated with gesture. Returns The event emitter for the gesture, which can be used to subscribe to gesture events defined in GestureType. |
| Static Functions | getGlobalEmitter(): IEventEmitter | • Function: Retrieves the global event emitter instance. If it doesn't exist, it creates a new one. Returns The global event emitter instance. |
| Static Functions | getObjectEmitter(obj: AObject): IEventEmitter | • Function: Retrieves the event emitter associated with a given object. Parameters • Returns The event emitter for the specified object. Returns undefined only when the input object is invalid or not supported. |
Examples
createEvent(eventType: number | UserEventType): IEvent
const event = APJS.EventManager.createEvent(myEventType);
defineUserEventType(eventName: number | string): UserEventType
const USER_EVENT_01: UserEventType = APJS.EventManager.defineUserEventType(42);
const USER_EVENT_02: UserEventType = APJS.EventManager.defineUserEventType('foo');
getGestureEmitter(): IEventEmitter
const emitter = APJS.EventManager.getGestureEmitter();
const callback = (event:APJS.IEvent) => {
const gestureInfo = event.args[0] as APJS.GestureInfo;
const offset = gestureInfo.endPoint.clone().subtract(gestureInfo.startPoint);
// Do something with drag offset
}
emitter.on(GestureType.Drag, callback)
getGlobalEmitter(): IEventEmitter
const emitter = APJS.EventManager.getGlobalEmitter();
emitter.emit(myEvent);
getObjectEmitter(obj: AObject): IEventEmitter
const emitter = APJS.EventManager.getObjectEmitter(myObject);
emitter.emit(myEvent);
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
onStart() {
// TODO: instantiate / use EventManager here
}
onUpdate(deltaTime: number) {
}
}