A global manager for animation playback.

Multiple Animation instances can be played back simultaneously. However, each animation must be associated with a particular key. Only one animation can be bound to a single key at the same time, so as to prevent conflicts between animations that try to assign different values to the same parameters of an animated object (e.g. multiple animations that want to modify the camera of the map, cfr. Map.cameraAnimationKey).

This class is a singleton.

An animation is started (Animation.onStart) when being added to the animation manager (putAnimation) and stopped (Animation.onStop) when it has reached the end of its duration, or when it is explicitly removed using removeAnimation. For looping animations the calls on the animation are repeated, thus Animation.onStart will be called each time a new iteration of the animation starts and Animation.onStop after the end of the duration of the animation. This will repeat until the animation is explicitly removed using removeAnimation.

Call order for an animation:

  1. AnimationManager.putAnimation(key, anim)
  2. anim.onStart() (once)
  3. anim.update(time) (multiple times while running)
  4. anim.onStop() (once)

Hierarchy

  • AnimationManager

Constructors

Methods

  • Returns the current animation for the passed keys, or undefined if there isn't one. Use this for instance to check if the current animation is yours before removing it.

    Parameters

    • key: any

      the objects with which to associate the animation

    Returns undefined | Animation

    the current animation for the passed object or undefined.

  • Starts the specified animation for the given key. Only one animation can be active for a key at any given time. Therefore, if another animation is already present for the specified key (and it is still running), that animation is first stopped and removed. The Promise returned by putAnimation will be rejected with an AbortError (for the animation that was aborted). You should attach a catch() handler to the putAnimation Promise to avoid "uncaught promise rejection" errors.

    Parameters

    • key: any

      the object with which to associate the animation

    • animation: Animation

      the animation to be played back

    • loop: boolean

      if true, the animation will run in a loop, thus it will only end when explicitly removed or replaced.

    • Optional abortSignal: AbortSignal

      An AbortSignal that can be used to abort hthe scheduled animation. When aborted, the putAnimation promise will be rejected with an AbortError. Make sure to attach a catch() handler to the putAnimation Promise to avoid "uncaught promise rejection" errors.

    Returns Promise<void>

  • Stops and removes the animation associated with the specified key, if any.

    Parameters

    • key: any

      the object from which to remove any currently running animation

    Returns void