SuperAPI AI 工具集

godot-genre-rhythm

编程与开发

查看项目

更新于 10-16 10:39

技能介绍

用途

该技能是为 Godot 引擎开发节奏游戏(音游)提供的专家级蓝图,覆盖音频同步、音符轨道(note highway)、判定系统、连击计分、输入处理与谱面/节拍图加载等核心系统。其内容基于 DDR、osu!、Beat Saber 的研究与实践总结,触发关键词包括 rhythm_game、audio_sync、timing_judgment、note_highway、combo_system、BPM_conductor、latency_compensation。

核心原则(反模式清单)

音频同步与逻辑

  • 不要用 Time.get_ticks_msec() / Time.get_ticks_usec() 作为歌曲时钟;应使用 AudioStreamPlayer.get_playback_position() + AudioServer.get_time_since_last_mix() - AudioServer.get_output_latency()(见 rhythm_conductor.gd)。
  • 不要在 _process() 中处理歌曲逻辑;应使用 _physics_process() 或 conductor 循环,保证与渲染帧无关的确定性计时。
  • 不要用 _process() 捕获打击输入;应使用 _input(event) 记录按键事件的精确时间戳。
  • 不要用引擎 time_scale 调整曲速;应使用 AudioStreamPlayer.pitch_scale,避免全局破坏物理逻辑。
  • 不要忽视音频延迟校准;应提供工具让玩家补偿硬件/蓝牙延迟(约 30-100ms)。
  • 不要用 _process 的 delta 作为歌曲时钟;应读取 conductor 的 get_song_time()(播放位置 + 混音 − 输出延迟)。
  • 不要在 CPU 上移动成千上万音符精灵;应使用基于着色器的轨道(UV 滚动)将轨道运动交给 GPU。
  • 不要用 yield 或 await 做节拍计时;应使用与音频时钟绑定的采样级精确 Delta 累加器。
  • 不要假设 BPM 恒定;conductor 应支持 Tempo Map 以处理复杂变速。

反馈与性能

  • 不要基于世界坐标(像素)判定输入;应针对歌曲已播放时间(毫秒)判定。
  • 不要用固定音高播放打击音;应加入约 ±5% 随机音高变化避免“机关枪”效果。
  • 不要对所有玩家使用极窄判定窗口(如 <25ms);应为新手提供更宽窗口。
  • 不要每个节拍都实例化音符节点;应使用对象池复用实例以避免密集谱面下的 GC 抖动。
  • 不要用标准 Area2D 信号做节奏打击;应在 conductor 循环中轮询输入并与目标时间戳比对。
  • 不要在主线程做 FFT 可视化;应使用 AudioEffectSpectrumAnalyzerInstance 做引擎侧分析。
  • 不要允许连打/乱按;应对 Miss 处罚或断连以维持游戏性。
  • 不要在游戏运行中用 load() 动态加载;应使用 ResourceLoader.load_threaded_request() 避免线程阻塞。
  • 不要忘记暂停 conductor/轨道;应与音频播放器的暂停状态同步,避免音乐停止时音符仍在滚动。

专家组件(scripts/)

实现匹配系统前必读:rhythm_conductor.gd(规范音频时钟)、input_judge_logic.gd(时间窗口判定)、note_object_pool.gd(对象池音符)、latency_calibrator.gd(玩家硬件偏移)。

原始专家模式:

  • rhythm_conductor.gd — 歌曲时间 = 播放位置 + 混音 − 输出延迟。
  • input_judge_logic.gd — 毫秒窗口对比歌曲时间(而非像素位置)。
  • note_object_pool.gd — 在密集谱面下复用音符实例。
  • latency_calibrator.gd — 在 conductor 上应用校准 UI 偏移。

模块化组件:

  • note_orchestrator.gd — 依据谱面数据生成/调度音符。
  • rhythm_scoring_system.gd — 由判定结果汇总分数。
  • score_combo_manager.gd — 连击/断连规则。
  • rhythm_ui_feedback.gd — 打击火花/判定文字。
  • beat_synced_animator.gd — 与 conductor 节拍锁定的视觉。
  • note_lane_manager.gd — 多轨道布局辅助。
  • dynamic_bpm_handler.gd — Tempo map / BPM 变化。
  • audio_spectrum_analyzer.gd — 频谱可视化(非时钟)。

不需要的轨道不要加载:若不是做反应式可视化,可跳过 audio_spectrum_analyzer.gd;恒定 BPM 曲目可跳过 dynamic_bpm_handler.gd。

脚本映射:基线 MusicConductor 采样 → rhythm_conductor.gd;JudgmentSystem → input_judge_logic.gd;谱面生成 → note_orchestrator.gd + note_object_pool.gd。

核心循环与决策要点

循环:校准延迟 → conductor 时钟 → 生成池化音符 → _input 判定 → 分数/连击 UI。

时钟决策:歌曲位置必须使用 rhythm_conductor.gd 的 get_song_time();视觉轨道位置由歌曲时间/节拍推导,不能以 _process delta 积分为真值;打击时间戳在 _input / _unhandled_input 捕获后与音符目标时间比对。

系统决策:判定窗口用 input_judge_logic.gd;计分/连击用 rhythm_scoring_system.gd + score_combo_manager.gd;谱面生成用 note_orchestrator.gd 与对象池;表现层用 rhythm_ui_feedback.gd / beat_synced_animator.gd。不要在技能内重新内联 MusicConductor / NoteHighway / JudgmentSystem / RhythmScoring 类,应加载脚本。

技能链与依赖

阶段:1 音频(godot-audio-systems,流时钟与延迟);2 输入(godot-input-handling,带时间戳的打击);3 UI(godot-ui-containers,轨道/HUD);4 性能(对象池/着色器,密集谱面);5 平衡(godot-monte-carlo-balancer,窗口难度分档)。

前置技能:godot-project-foundations(音频延迟项目设置、总线命名、输入映射轨道动作需先存在)、godot-audio-systems、godot-input-handling、godot-gdscript-mastery。互补技能:godot-tweening、godot-shaders-basics、godot-particles、godot-ui-containers、godot-save-load-systems、godot-autoload-architecture、godot-signal-architecture。下游:godot-performance-optimization、godot-monte-carlo-balancer。路由:godot-master。

常见陷阱

用 Time.get_ticks_* 作时钟 → 改用播放位置 + 混音 − 延迟;在 _process 中判定 → 用 _input + 歌曲时间;每个音符都实例化 → 使用 note_object_pool.gd。

适用场景与限制

适用于 Godot 中开发节奏游戏、或需要音频与操作精确同步的玩法系统;涉及音游时钟、判定窗口、轨道滚动、连击计分与延迟校准。深度内容需查阅 references/rhythm-systems-deep.md,首次接线时不要加载,应先用捆绑的 scripts/。官方文档链接(如 Sync the gameplay with audio and music、Audio streams、Audio buses、AudioServer、AudioStreamPlayer 等)按需查阅,路由到同领域时再加载相关技能,不要预先加载整张技能网络。