contextUpdateSound 上下文方法 - 更新音效层
contextUpdateSound
类型: MethodDeclaration
所属类: AnimationPlayer
定义位置: animation.ts
描述
上下文方法 - 更新音效层
参数 frame: 动画图层当前帧的数据
参数
| 参数名 | 类型 | 描述 | 默认值 | 
|---|---|---|---|
| this | AnimationFrameContext | - | - | 
| frame | AnimationSoundFrame | - | - | 
返回值
类型: void
源代码
位置: 第 1257 行
private static contextUpdateSound(this: AnimationFrameContext, frame: AnimationSoundFrame): void {
    // 如果当前帧是关键帧
    const animation = this.animation
    if (animation.paused) return
    if (animation.index < frame.start + 1) {
      // 如果当前帧未播放过
      const version = animation.cycleIndex * animation.length + Math.floor(animation.index)
      if (this.version !== version) {
        this.version = version
        // 在动画的位置播放衰减音效
        if (frame.sound && animation.position) {
          const layer = this.layer as AnimationSoundLayer
          const speed = layer.playbackRate === 'inherit' ? animation.speed : 1
          if (animation.isUIComponent) {
            AudioManager.se.play(frame.sound, frame.volume, speed)
          } else {
            AudioManager.se.playAt(frame.sound, animation.position, frame.volume, speed)
          }
        }
      }
    }
  }
文档生成时间:2025/7/21 20:53:39