playAnimation()

in src/core/animpack/AnimationFeature.js [1054:1100]


  playAnimation(layerName, animationName, seconds, easingFn) {
    const layer = this._layerMap[layerName];

    if (layer === undefined) {
      const e = `Cannot play animation ${animationName} on layer ${layerName} for host ${this._host.id}. No layer exists with this name.`;
      return Deferred.reject(e);
    }

    // Notify that a new animation has begun
    this.emit(this.constructor.EVENTS.playAnimation, {
      layerName,
      animationName,
    });

    return layer.playAnimation(
      animationName,
      seconds,
      easingFn,
      () => {
        // Notify that an animation has stopped
        this.emit(this.constructor.EVENTS.stopAnimation, {
          layerName,
          animationName,
        });
      },
      undefined,
      () => {
        // Notify that an animation has been interrupted
        this.emit(this.constructor.EVENTS.interruptAnimation, {
          layerName,
          animationName,
        });
      },
      ({name, canAdvance, isQueueEnd}) => {
        if (layer.currentAnimation === animationName) {
          // Notify that a new animation has begun
          this.emit(this.constructor.EVENTS.playNextAnimation, {
            layerName,
            animationName,
            nextQueuedAnimation: name,
            canAdvance,
            isQueueEnd,
          });
        }
      }
    );
  }