The event manager class, used to manage events and execute them at the correct time.

Type Parameters

  • Events extends string = string

Constructors

  • Creates a new event manager.

    Type Parameters

    • Events extends string = string

    Parameters

    • Optionalconfig: EventManagerConfig

      The config to use for this event manager.

    • Optionalevents: readonly Events[]

      The events to add to the event manager. These events will be added to the event manager's callback events, although you could omit this and add events manually (though this is not recommended as you won't get type checking).

    Returns EventManager<Events>

Properties

addEvent: {
    (name: string, type: "interval" | "timeout" | EventTypes, delay: number | Decimal, callbackFn: ((dt: number) => void)): void;
    (event: EventInit): void;
} = ...

Adds a new event. Alias for EventManager.setEvent. Only here for backwards compatibility.

Type declaration

    • (name, type, delay, callbackFn): void
    • Adds a new event or changes an existing event to the event system. If you want to add a callback event, use EventManager.on instead.

      Parameters

      • name: string

        The name of the event. If an event with this name already exists, it will be overwritten.

      • type: "interval" | "timeout" | EventTypes

        The type of the event, either "interval" or "timeout".

      • delay: number | Decimal

        The delay in milliseconds before the event triggers. (NOTE: If delay is less than the framerate, it will at trigger at max, once every frame.)

      • callbackFn: ((dt: number) => void)

        The callback function to execute when the event triggers.

          • (dt): void
          • Parameters

            • dt: number

            Returns void

      Returns void

      const myEventManger = new eventManager();
      // Add an interval event that executes every 2 seconds.
      myEventManger.addEvent("IntervalEvent", "interval", 2000, () => {
      console.log("Interval event executed.");
      });

      // Add a timeout event that executes after 5 seconds.
      myEventManger.addEvent("TimeoutEvent", "timeout", 5000, () => {
      console.log("Timeout event executed.");
      });
    • (event): void
    • Parameters

      Returns void

Use EventManager.setEvent instead.

The config object

Methods

  • Changes the framerate of the event manager.

    Parameters

    • fps: number

      The new framerate to use.

    Returns void

  • Removes a timer event from the event manager. Does not remove callback events.

    Parameters

    • name: string

      The name of the event to remove.

    Returns void

    myEventManger.removeEvent("IntervalEvent"); // Removes the interval event with the name "IntervalEvent".
    
  • Adds a new event or changes an existing event to the event system. If you want to add a callback event, use EventManager.on instead.

    Parameters

    • name: string

      The name of the event. If an event with this name already exists, it will be overwritten.

    • type: "interval" | "timeout" | EventTypes

      The type of the event, either "interval" or "timeout".

    • delay: number | Decimal

      The delay in milliseconds before the event triggers. (NOTE: If delay is less than the framerate, it will at trigger at max, once every frame.)

    • callbackFn: ((dt: number) => void)

      The callback function to execute when the event triggers.

        • (dt): void
        • Parameters

          • dt: number

          Returns void

    Returns void

    const myEventManger = new eventManager();
    // Add an interval event that executes every 2 seconds.
    myEventManger.addEvent("IntervalEvent", "interval", 2000, () => {
    console.log("Interval event executed.");
    });

    // Add a timeout event that executes after 5 seconds.
    myEventManger.addEvent("TimeoutEvent", "timeout", 5000, () => {
    console.log("Timeout event executed.");
    });
  • Parameters

    Returns void

  • Warps time by a certain amount. Note: This will affect the stored creation time of timeout events.

    Parameters

    • dt: number

      The time to warp by (in milliseconds).

    Returns void