ThorVG WebCanvas API - v1.1.4
    Preparing search index...

    Class LottieAnimation

    Animation controller with the Lottie extensions: markers, slots, etc.

    Extends Animation, so loading and playback work identically.

    // Play a named range (Marker)
    const animation = new TVG.LottieAnimation();
    animation.load(lottieData);
    canvas.add(animation.picture);

    animation.segment('walk-cycle');
    animation.play(() => canvas.update().render());
    // Override a property of the Lottie (Slot)
    const animation = new TVG.LottieAnimation();
    animation.load(lottieData);

    const id = animation.gen({
    ball_col: { p: { a: 0, k: [0, 1, 0, 1] } },
    });
    animation.apply(id);
    canvas.update().render();

    Hierarchy (View Summary)

    Index
    • get picture(): Picture | null

      Get the Picture object that contains the animation content The Picture is owned by the Animation and should not be manually disposed

      Returns Picture | null

    • get ptr(): number

      Gets the WASM pointer for this object Returns 0 if object has been disposed (error handled by global handler)

      Returns number

    • get isDisposed(): boolean

      Check if this object has been disposed

      Returns boolean

    • Cleanup function to be implemented by subclasses

      Parameters

      • ptr: number

        The WASM pointer to clean up

      Returns void

    • Load Lottie animation from raw data

      Parameters

      • data: string | Uint8Array<ArrayBufferLike>

        Lottie JSON data as Uint8Array or string

      Returns this

    • Play the animation

      Parameters

      • OptionalonFrame: (frame: number) => void

        Optional callback called on each frame update

      Returns this

    • Set the playback segment by marker name.

      Markers are designated at the design level, so the caller must know the marker name in advance. Setting a marker discards any previously set segment.

      Parameters

      • marker: string | null

        The marker name, or null to reset to the full timeline

      Returns this

      animation.segment('walk-cycle').play();
      animation.segment(null); // back to the whole animation
    • Set the playback segment (for partial playback)

      Parameters

      • begin: number

        Segment begin frame

      • end: number

        Segment end frame

      Returns this

    • Get the number of markers in the loaded animation

      Returns number

      The marker count, or 0 if the animation has no markers

    • Get the name and frame range of a marker by index

      Parameters

      • idx: number

        Zero-based marker index

      Returns LottieMarker | null

      The marker, or null if the index is out of range

      for (let i = 0; i < animation.markersCnt(); i++) {
      const marker = animation.marker(i);
      console.log(`${marker.name}: ${marker.begin} - ${marker.end}`);
      }
    • Generate a slot from Lottie slot data, for overriding animation properties

      Parameters

      • slot: string | LottieSlotData

        The slot data. Pass an object and it is serialized for you, or a raw JSON string to hand through untouched - useful when the data already arrives as text.

      Returns number

      A non-zero slot ID on success

      The slot format requires each entry to wrap its value in p. An entry without it parses to an empty property, so gen() still returns a valid ID but the override does nothing.

      const id = animation.gen({
      fill_color: { p: { a: 0, k: [1, 0, 0] } },
      });
      animation.apply(id);
    • Apply a previously generated slot to the animation

      Parameters

      • id: number

        The slot ID from gen, or 0 to reset all applied slots

      Returns this

    • Delete a previously generated slot

      Parameters

      • id: number

        The slot ID from gen

      Returns this

    • Set the quality level for Lottie effects such as blur and shadows

      Parameters

      • value: number

        Quality level from 0 (fastest) to 100 (best), default 50. Values outside the range are clamped.

      Returns this

    • Beta

      Retrieves the master playback volume of the Lottie animation.

      Returns number

      The current master playback volume, otherwise 0 if the animation is not loaded.

    • Beta

      Sets the master playback volume of the Lottie animation.

      The specified volume is applied to all media assets in the animation. Each media asset preserves its own volume, and the effective playback volume is calculated by multiplying the master volume by the media asset's volume.

      A value of 1.0 preserves the original volume. A value of 0.0 mutes all media. Values greater than 1.0 amplify the playback volume.

      The recommended range is [0.0, 2.0].

      Parameters

      • value: number

        Master playback volume.

      Returns this

    • Beta

      Sets the audio resolver callback for the Lottie audio layers.

      The built-in backend stops while a resolver is set, so the resolver takes on every audio layer of the animation.

      Parameters

      • callback: AudioResolver | null

        The resolver, or null to hand the layers back to the built-in backend.

      Returns this

      animation.resolver((info) => {
      if (info.active) {
      //Start or seek playback of info.src.
      } else {
      //Stop playback of info.src.
      }
      });