Important Note: All code examples in this skill are based on Godot 4.5 best practices, using GDScript syntax. Ensure it is used in a Godot 4.x environment, and pay attention to the new API changes in the AnimationPlayer and Tween systems.
Skill Overview
godot-animation-studio is an intelligent skill specifically for Godot game resource creation and animation production, capable of automatically completing the full resource production workflow of sprite import and slicing, animation configuration and optimization, particle special effects creation, sound effect integration, and resource management based on the user's natural language descriptions.
Core Features
🎨 Sprite Resource Management
- Smart Import: Automatically import and configure sprite atlases
- Slice Optimization: Smart sprite slicing and grid layout
- Format Conversion: Supports conversion and optimization of multiple image formats
- Batch Processing: Batch import and process large amounts of sprite resources
🎬 Animation System Production
- AnimationPlayer Configuration: Create and configure animation players
- AnimationTree State Machine: Complex animation state machine design
- Skeletal Animation: 2D skeletal animation and skinning system
- Animation Blending: Smooth animation transitions and blending
✨ Particle Special Effects Production
- GPUParticles2D/3D: GPU particle system configuration
- CPUParticles2D/3D: CPU particle system optimization
- Particle Materials: Custom particle shaders and materials
- Special Effects Composition: Composition and hierarchy management of complex special effects
🎵 Sound Effect Resource Integration
- Audio Import: Import and optimization of multiple audio formats
- Sound Effect Management: Classification and management of sound effect libraries
- 3D Sound Effects: Spatial sound effects and audio listener settings
- Dynamic Sound Effects: Procedural sound effect generation and modulation
Usage
Character Animation Production
用户: "我需要为一个骑士角色制作待机、行走、攻击、受伤四种动画"
系统: 自动实现:
- 导入骑士精灵图集
- 智能切片和命名规范
- 创建AnimationPlayer和动画轨道
- 配置动画时长和过渡
- 创建AnimationTree状态机
- 添加动画事件和回调
Particle Special Effects Production
用户: "创建一个火焰爆炸特效,包含火花、烟雾和冲击波"
系统: 智能生成:
- GPUParticles2D火焰粒子系统
- 烟雾粒子配置
- 冲击波扩散效果
- 粒子材质和着色器
- 多层级特效组合
- 音效同步集成
UI Animation Production
用户: "为按钮制作悬停、点击、禁用三种状态的动画"
系统: 全面开发:
- 按钮精灵状态导入
- 悬停缩放动画
- 点击弹跳效果
- 禁用淡出效果
- 平滑过渡配置
- 音效集成
Environmental Animation Production
用户: "制作一个动态的森林场景,包含摇曳的树木和飘落的叶子"
系统: 完整实现:
- 树木摇摆动画
- 叶子飘落粒子
- 风力方向变化
- 动态光照效果
- 环境音效集成
Workflow
1. Resource Analysis
# 分析资源需求
- 识别动画类型和复杂度
- 确定资源格式和规格
- 评估制作时间和技术要求
2. Resource Preparation
# 准备资源素材
- 导入和优化图片资源
- 处理音频文件
- 创建基础材质和着色器
3. Animation Production
# 制作动画内容
- 创建动画时间轴
- 设置关键帧和曲线
- 配置动画过渡和混合
4. Integration Testing
# 测试和优化
- 运行时性能测试
- 视觉效果调整
- 音画同步验证
MCP Tool Integration
Resource Management Tools
import_asset- Import resource filescreate_resource- Create animation and special effects resourcesconfigure_resource- Configure resource propertiesoptimize_asset- Optimize resource size and quality
Animation Tools
create_animation_player- Create animation playercreate_animation_tree- Create animation state machineadd_animation_track- Add animation tracksset_animation_key- Set animation keyframes
Particle System Tools
create_particles- Create particle systemconfigure_particles- Configure particle parameterscreate_particle_material- Create particle materialsadd_particle_emitter- Add particle emitters
Audio Tools
import_audio- Import audio filescreate_audio_stream- Create audio streamsconfigure_audio_bus- Configure audio busesset_3d_audio- Set 3D audio effects
Animation Production System
2D Character Animation
# 智能角色动画生成器
class_name CharacterAnimationGenerator extends Node
@export var character_name: String
@export var animation_types: Array[String] = ["idle", "walk", "run", "jump", "attack", "hurt"]
func generate_character_animations(sprite_sheet: Texture2D) -> Dictionary:
var animations = {}
var frame_size = Vector2(64, 64)
# 自动切片精灵图集
var sprite_frames = SpriteFrames.new()
_slice_sprite_sheet(sprite_sheet, frame_size, sprite_frames)
# 为每种动画类型创建AnimationPlayer资源
for anim_type in animation_types:
var animation = Animation.new()
_create_character_animation(animation, anim_type, sprite_frames)
animations[anim_type] = animation
return animations
func _create_character_animation(animation: Animation, anim_type: String, frames: SpriteFrames) -> void:
var track_index = animation.add_track(Animation.TYPE_VALUE)
animation.track_set_path(track_index, Sprite2D.get_path() + ":frame")
match anim_type:
"idle":
_create_idle_animation(animation, track_index, frames)
"walk":
_create_walk_animation(animation, track_index, frames)
"attack":
_create_attack_animation(animation, track_index, frames)
State Machine System
# 智能动画状态机生成器
class_name AnimationStateMachineGenerator extends Node
@export var state_transitions: Dictionary = {}
func create_state_machine(character_name: String) -> AnimationNodeStateMachine:
var state_machine = AnimationNodeStateMachine.new()
# 创建基础状态节点
var idle_state = AnimationNodeAnimation.new()
idle_state.animation = "idle"
var walk_state = AnimationNodeAnimation.new()
walk_state.animation = "walk"
var attack_state = AnimationNodeAnimation.new()
attack_state.animation = "attack"
# 添加状态到状态机
state_machine.add_node("Idle", idle_state)
state_machine.add_node("Walk", walk_state)
state_machine.add_node("Attack", attack_state)
# 创建状态转换
_create_transition(state_machine, "Idle", "Walk", "is_moving")
_create_transition(state_machine, "Walk", "Idle", "!is_moving")
_create_transition(state_machine, "Idle", "Attack", "attack_pressed")
_create_transition(state_machine, "Attack", "Idle", "animation_finished")
return state_machine
Particle Effects System
Intelligent Particle Generation
# 粒子特效生成器
class_name ParticleEffectGenerator extends Node
func create_explosion_effect(position: Vector2) -> GPUParticles2D:
var particles = GPUParticles2D.new()
particles.position = position
particles.emitting = true
particles.one_shot = true
# 配置火焰粒子
var fire_material = create_fire_material()
particles.process_material = fire_material
# 设置粒子参数
particles.amount = 100
particles.lifetime = 2.0
particles.explosiveness = 0.8
particles.initial_velocity_min = 100.0
particles.initial_velocity_max = 300.0
return particles
func create_fire_material() -> ParticleProcessMaterial:
var material = ParticleProcessMaterial.new()
# 颜色渐变
var gradient = Gradient.new()
gradient.add_color_point(0.0, Color.YELLOW)
gradient.add_color_point(0.5, Color.ORANGE)
gradient.add_color_point(1.0, Color.RED)
material.color = gradient
material.scale_min = 0.1
material.scale_max = 0.3
material.scale_random = 0.5
return material
Complex Effect Combinations
# 多层级特效系统
class_name CompositeEffectSystem extends Node
var effect_layers: Array[GPUParticles2D] = []
func create_magic_spell_effect(cast_position: Vector2, target_position: Vector2) -> Node2D:
var effect_container = Node2D.new()
# 创建魔法轨迹
var trail_particles = create_magic_trail(cast_position, target_position)
effect_container.add_child(trail_particles)
# 创建爆炸效果
var explosion_particles = create_magic_explosion(target_position)
effect_container.add_child(explosion_particles)
# 创建光环效果
var aura_particles = create_magic_aura(target_position)
effect_container.add_child(aura_particles)
return effect_container
func create_magic_trail(start: Vector2, end: Vector2) -> GPUParticles2D:
var trail = GPUParticles2D.new()
trail.emitting = true
# 配置轨迹粒子
var trail_material = ParticleProcessMaterial.new()
trail_material.direction = Vector3(end - start, 0).normalized()
trail_material.initial_velocity_min = 200.0
trail_material.initial_velocity_max = 300.0
# 紫色魔法粒子
var gradient = Gradient.new()
gradient.add_color_point(0.0, Color.MAGENTA)
gradient.add_color_point(1.0, Color.PURPLE)
trail_material.color = gradient
trail.process_material = trail_material
return trail
Sound Effects Integration System
Intelligent Sound Effect Management
# 音效管理器
class_name AudioManager extends Node
@export var audio_bus_layout: AudioBusLayout
var sound_library: Dictionary = {}
var music_player: AudioStreamPlayer
var sound_players: Array[AudioStreamPlayer]
func _ready() -> void:
_setup_audio_bus()
_create_sound_players()
_load_default_sounds()
func play_sound(sound_name: String, position: Vector2 = Vector2.ZERO) -> void:
var audio_stream = sound_library.get(sound_name)
if not audio_stream:
push_warning("Sound not found: " + sound_name)
return
var player = _get_available_player()
player.stream = audio_stream
player.play()
# 如果指定了位置,使用2D音效
if position != Vector2.ZERO:
var audio_player_2d = AudioStreamPlayer2D.new()
audio_player_2d.stream = audio_stream
audio_player_2d.global_position = position
# ✅ 正确:安全检查场景树和添加节点
if get_tree() and get_tree().current_scene:
get_tree().current_scene.add_child(audio_player_2d)
audio_player_2d.play()
await audio_player_2d.finished
# ✅ 正确:使用延迟删除避免在回调中直接删除
audio_player_2d.call_deferred("queue_free")
else:
push_warning("场景树未准备就绪,无法播放2D音效")
func play_footstep_sound(surface_type: String) -> void:
var footstep_variants = sound_library.get("footstep_" + surface_type, [])
if footstep_variants.size() > 0:
var random_sound = footstep_variants[randi() % footstep_variants.size()]
play_sound(random_sound)
Dynamic Sound Effect Generation
# 程序化音效生成器
class_name ProceduralAudioGenerator extends Node
func generate_laser_sound() -> AudioStream:
var generator = AudioStreamGenerator.new()
generator.sample_rate = 44100
generator.buffer_length = 0.5
var playback = generator.instantiate_playback()
var frames_to_fill = int(generator.sample_rate * generator.buffer_length)
# 生成激光音效(频率扫描)
for i in range(frames_to_fill):
var t = float(i) / generator.sample_rate
var frequency = 800.0 - 400.0 * t # 从800Hz扫描到400Hz
var amplitude = exp(-t * 3.0) # 指数衰减
var sample = amplitude * sin(2.0 * PI * frequency * t)
playback.push_frame(Vector2.ONE * sample)
return generator
func generate_impact_sound(velocity: float) -> AudioStream:
var generator = AudioStreamGenerator.new()
generator.sample_rate = 44100
generator.buffer_length = 0.2
var playback = generator.instantiate_playback()
var frames_to_fill = int(generator.sample_rate * generator.buffer_length)
# 基于速度生成冲击音效
var base_frequency = clamp(velocity * 10.0, 100.0, 1000.0)
for i in range(frames_to_fill):
var t = float(i) / generator.sample_rate
var amplitude = exp(-t * 10.0) # 快速衰减
var frequency = base_frequency + randf_range(-50.0, 50.0)
var sample = amplitude * (sin(2.0 * PI * frequency * t) + randf_range(-0.1, 0.1))
playback.push_frame(Vector2.ONE * sample)
return generator
Resource Optimization System
Intelligent Compression
# 资源优化器
class_name AssetOptimizer extends Node
func optimize_texture(texture: Texture2D, target_size: Vector2) -> Texture2D:
var image = texture.get_image()
# 调整尺寸
image.resize(target_size.x, target_size.y, Image.INTERPOLATE_LANCZOS)
# 压缩格式
var compressed_texture = ImageTexture.new()
compressed_texture.set_image(image)
return compressed_texture
func optimize_audio(audio_stream: AudioStream) -> AudioStream:
if audio_stream is AudioStreamMP3:
# 转换为OGG格式以获得更好的压缩比
var ogg_stream = AudioStreamOggVorbis.new()
# 转换逻辑...
return ogg_stream
return audio_stream
Batch Processing
# 批量资源处理器
class_name BatchAssetProcessor extends Node
func process_sprite_sheets(input_folder: String, output_folder: String) -> void:
var dir = DirAccess.open(input_folder)
if not dir:
push_error("Cannot open input folder: " + input_folder)
return
dir.list_dir_begin()
var file_name = dir.get_next()
while file_name != "":
if file_name.ends_with(".png"):
var input_path = input_folder + "/" + file_name
var output_path = output_folder + "/" + file_name.get_basename() + ".tres"
_process_sprite_sheet(input_path, output_path)
file_name = dir.get_next()
func _process_sprite_sheet(input_path: String, output_path: String) -> void:
var texture = load(input_path)
var sprite_frames = SpriteFrames.new()
# 自动检测和切片
var frame_size = _detect_frame_size(texture)
_slice_texture(texture, frame_size, sprite_frames)
# 保存资源
ResourceSaver.save(sprite_frames, output_path)
Intelligent Features
Automated Workflow
- Batch Processing: One-click processing of large numbers of resource files
- Intelligent Detection: Automatically detects sprite dimensions and animation frames
- Format Optimization: Automatically selects the optimal resource format
- Quality Balance: Finds the best balance between quality and size
AI-Assisted Production
- Animation Prediction: Predicts animation requirements based on character type
- Effect Recommendations: Recommends suitable effects based on the scene
- Sound Effect Matching: Automatically matches sound effects and visual effects
- Style Consistency: Ensures all resources have a consistent style
Real-Time Preview
- Instant Preview: Real-time preview of effects during production
- Performance Monitoring: Monitors the impact of resources on performance
- Version Comparison: Compares the effect differences between different versions
- Team Collaboration: Multi-person collaborative production and review
Example Implementation
Complete Character Animation System
# 智能角色动画系统
class_name SmartCharacterAnimationSystem extends Node
@export var character_data: CharacterData
func generate_complete_animation_system() -> Node:
var animation_container = Node.new()
animation_container.name = character_data.character_name + "_Animations"
# 创建精灵帧资源
var sprite_frames = create_sprite_frames()
# 创建动画播放器
var animation_player = create_animation_player(sprite_frames)
animation_container.add_child(animation_player)
# 创建动画状态机
var animation_tree = create_animation_tree(sprite_frames)
animation_container.add_child(animation_tree)
# 创建音效管理
var audio_manager = create_character_audio_manager()
animation_container.add_child(audio_manager)
return animation_container
func create_sprite_frames() -> SpriteFrames:
var frames = SpriteFrames.new()
for animation_name in character_data.animations.keys():
var animation_data = character_data.animations[animation_name]
_load_animation_frames(frames, animation_name, animation_data)
return frames
Quality Assurance
Visual Quality
- Frame Rate Consistency: Ensures stable animation frame rate
- Color Accuracy: Maintains accurate color reproduction
- Edge Processing: Optimizes sprite edges and anti-aliasing
- Visual Consistency: Ensures a unified overall visual style
Technical Quality
- Performance Optimization: Optimizes resource loading and runtime performance
- Memory Management: Reasonably controls memory usage
- Compatibility: Ensures cross-platform compatibility
- Scalability: Facilitates the subsequent addition of new resources
User Experience
- Loading Speed: Optimizes resource loading time
- Smoothness: Ensures smooth animation and effects
- Audio-Video Sync: Precise audio-video synchronization
- Response Speed: Fast interactive response
Usage Restrictions and Precautions
Technical Limitations
- File Size: Large resource files may affect performance
- Format Support: Some special formats may be incompatible
- Hardware Requirements: Complex effects require higher hardware configurations
Best Practices
- Resource Optimization: Regularly optimize and compress resources
- Backup Management: Make backups of resource files
- Version Control: Use version control to manage resources
Troubleshooting
FAQ
- Animation stuttering: Check frame rate and resource size
- Effects not displaying: Verify particle system configuration
- Sound effect playback failure: Check audio file format
- Slow resource loading: Optimize resource size and format
Debugging tips
- Use Godot's debugging tools
- Check console error messages
- Monitor performance metrics
- Troubleshoot step by step
Changelog
v1.0.0 (current version)
- Basic animation production features
- Particle effects system
- Sound effect integration features
- Resource optimization tools
Planned features
- AI animation generation
- Real-time collaborative production
- More effect templates
- Advanced sound effect processing
Best practices for Camera2D and animation system integration
🎬 Character display issue diagnostic system
# 角色可见性诊断器 - 解决角色看不到的问题
class_name CharacterVisibilityDiagnostic extends Node
@export var character: AnimatedSprite2D
@export var camera: Camera2D
@export var diagnostic_enabled: bool = true
func run_diagnostic_check() -> void:
print("=== 角色可见性诊断开始 ===")
# 1. 检查AnimatedSprite2D配置
_check_animated_sprite_configuration()
# 2. 检查SpriteFrames资源
_check_sprite_frames_resource()
# 3. 检查相机配置
_check_camera_configuration()
# 4. 检查世界坐标和视野关系
_check_world_coordinates()
print("=== 角色可见性诊断完成 ===")
func _check_animated_sprite_configuration() -> void:
if not character:
print("❌ 错误: AnimatedSprite2D引用为空")
return
print("✅ AnimatedSprite2D配置正常")
print(" - 位置:", character.global_position)
print(" - 可见性:", character.visible)
if character.sprite_frames:
print("✅ SpriteFrames资源已加载")
print(" - 可用动画:", character.sprite_frames.get_animation_names())
else:
print("❌ 错误: SpriteFrames资源为空")
func _check_camera_configuration() -> void:
if not camera:
print("❌ 错误: Camera2D引用为空")
return
print("✅ Camera2D配置正常")
print(" - 位置:", camera.global_position)
print(" - 缩放:", camera.zoom)
print(" - 平滑跟随:", camera.position_smoothing_enabled)
📷 Smart camera follow system
# 动画驱动的相机系统
class_name AnimationDrivenCameraSystem extends Node
@export var target_character: AnimatedSprite2D
@export var camera: Camera2D
@export var follow_speed: float = 5.0
# 动画状态对应的相机参数
var animation_camera_settings = {
"idle": {"zoom": Vector2(1.0, 1.0), "offset": Vector2(0, -80)},
"walk": {"zoom": Vector2(1.1, 1.1), "offset": Vector2(0, -90)},
"attack": {"zoom": Vector2(1.2, 1.2), "offset": Vector2(0, -70)}
}
func _process(delta):
if target_character and camera:
_update_camera_follow(delta)
func _update_camera_follow(delta: float) -> void:
var current_anim = target_character.animation
var settings = animation_camera_settings.get(current_anim, animation_camera_settings["idle"])
# 平滑跟随
var target_position = target_character.global_position + settings.offset
camera.global_position = camera.global_position.lerp(target_position, follow_speed * delta)
camera.zoom = camera.zoom.lerp(settings.zoom, follow_speed * delta * 0.5)
🛠️ Common problem solutions
Problem 1: Character falls off the screen
# 修复角色物理和位置
func fix_character_physics(character: CharacterBody2D):
# 设置合理的初始位置
character.position = Vector2(character.position.x, 145) # 地面以上
# 配置物理参数
if character.has_method("set_gravity_scale"):
character.set_gravity_scale(1.0)
# 确保启用碰撞
character.set_collision_layer_value(1, true)
character.set_collision_mask_value(1, true)
Problem 2: Camera does not follow the character
# 修复相机跟随
func fix_camera_follow(camera: Camera2D, target: Node2D):
camera.position_smoothing_enabled = true
camera.position_smoothing_speed = 5.0
# 设置相机边界
camera.limit_left = -1024
camera.limit_right = 1024
camera.limit_top = -600
camera.limit_bottom = 600
Problem 3: SpriteFrames resource missing
# 修复SpriteFrames资源
func fix_sprite_frames(character: AnimatedSprite2D):
if not character.sprite_frames:
# 创建默认SpriteFrames
var frames = SpriteFrames.new()
# 添加基本动画
_add_default_animations(frames)
character.sprite_frames = frames
func _add_default_animations(frames: SpriteFrames):
# 使用颜色块作为占位符纹理
var placeholder_texture = _create_colored_texture(Color.RED, Vector2(64, 64))
# 添加idle动画
frames.add_animation("idle")
frames.add_frame("idle", placeholder_texture)
# 添加walk动画
frames.add_animation("walk")
frames.add_frame("walk", placeholder_texture)
frames.add_frame("walk", placeholder_texture)
func _create_colored_texture(color: Color, size: Vector2) -> ImageTexture:
var image = Image.create(size.x, size.y, false, Image.FORMAT_RGB8)
image.fill(color)
var texture = ImageTexture.new()
texture.set_image(image)
return texture
🎯 Debugging tools
# 实时调试显示
class_name AnimationDebugDisplay extends Control
@export var character: AnimatedSprite2D
@export var camera: Camera2D
func _process(delta):
queue_redraw()
func _draw():
if not character or not camera:
return
# 绘制角色边界框
var char_rect = Rect2(character.global_position - camera.global_position + size/2,
character.sprite_frames.get_frame_texture(character.animation, 0).get_size())
draw_rect(char_rect, Color.GREEN, false, 2.0)
# 绘制相机视野中心
var center = size / 2
draw_circle(center, 5.0, Color.RED)
# 显示状态信息
var debug_text = "角色: %s\n位置: %s\n动画: %s\n相机: %s" % [
character.name,
character.global_position,
character.animation,
camera.global_position
]
draw_string(ThemeDB.fallback_font, Vector2(10, 30), debug_text, HORIZONTAL_ALIGNMENT_LEFT, -1, 16, Color.WHITE)
Skill status: ✅ Available Last updated: 2025-11-09 Compatibility: Godot 4.5+ New features: Camera2D integration, character display issue diagnosis Dependencies: Godot MCP toolset + animation production knowledge