npx skills add https://github.com/bfollington/terma --skill bevy一项专门用于使用 Bevy 游戏引擎开发游戏和应用程序的技能,基于构建复杂 Bevy 项目的实际经验。
在以下情况下调用此技能:
如果使用 Bevy 0.17,请注意重大的 API 变更:
MeshMaterial3d<T> 中(而不是 Handle<T>)commands.trigger()、add_observer())完整的 Bevy 0.17 迁移指南和示例请参见 references/bevy_specific_tips.md。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
注册表示例是你的圣经。 在实现新功能之前,务必先检查它们。
位置:
~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy-0.17.1/examples
有许多示例涵盖了 Bevy 开发的各个方面。查看相关示例以了解最佳实践和工作模式。
使用插件将你的应用分解为离散的模块。这可以改善组织性并使代码易于查找。
pub struct CombatPlugin;
impl Plugin for CombatPlugin {
fn build(&self, app: &mut App) {
app
.add_event::<DamageEvent>()
.add_systems(Update, (process_damage, check_death));
}
}
详细的插件模式和示例请参见 references/bevy_specific_tips.md。
纯粹的 ECS 需要仔细的数据建模。 在一个文件中搜索庞大的系统列表是很困难的!
在实现之前:
领域驱动设计指导请参见 references/bevy_specific_tips.md。
Bevy 是一个实体组件系统引擎。始终以数据(组件)和转换(系统)的方式思考,而不是对象和方法。
关注点分离:
保持组件专注:
// ✅ 良好:小巧、专注的组件
#[derive(Component)]
pub struct Health { pub current: f32, pub max: f32 }
#[derive(Component)]
pub struct Armor { pub defense: f32 }
// ❌ 不好:庞大的组件
#[derive(Component)]
pub struct CombatStats {
pub health: f32,
pub armor: f32,
pub strength: f32,
// ... 对于只有部分属性的实体会浪费内存
}
通过 impl 块添加辅助方法:
impl Health {
pub fn is_alive(&self) -> bool {
self.current > 0.0
}
pub fn percentage(&self) -> f32 {
self.current / self.max
}
}
详细的组件模式请参见 references/ecs_patterns.md。
按依赖关系对系统排序:
.add_systems(
Update,
(
// 1. 输入处理
handle_input,
// 2. 状态变化
process_events,
update_state,
// 3. 从状态推导属性
calculate_derived_values,
// 4. 视觉更新
update_materials,
update_animations,
// 5. UI 更新(必须最后运行)
update_ui_displays,
),
)
使用变更检测进行优化:
// 仅处理 Health 发生变化的实体
pub fn update_health_bar(
query: Query<(&Health, &mut HealthBar), Changed<Health>>,
) {
for (health, mut bar) in query.iter_mut() {
bar.width = health.percentage() * 100.0;
}
}
详细的查询模式和系统设计请参见 references/ecs_patterns.md。
开发(更快的迭代):
cargo build --features bevy/dynamic_linking
快速检查:
cargo check
发布(生产):
cargo build --release
不要随意删除目标二进制文件! Bevy 从头开始重新构建需要几分钟。
cargo clean详细的构建优化和版本管理请参见 references/bevy_specific_tips.md。
cargo checkcargo check 然后 cargo build --features bevy/dynamic_linking验证点 - 让用户在以下里程碑进行测试:
Bevy 使用类似 flexbox 的布局系统。遵循标记组件模式:
1. 创建标记组件:
#[derive(Component)]
pub struct HealthBar;
#[derive(Component)]
pub struct ScoreDisplay;
2. 在 Startup 中设置:
pub fn setup_ui(mut commands: Commands) {
commands.spawn((
HealthBar,
Node {
position_type: PositionType::Absolute,
left: Val::Px(10.0),
top: Val::Px(10.0),
width: Val::Px(200.0),
height: Val::Px(20.0),
..default()
},
BackgroundColor(Color::srgba(0.8, 0.2, 0.2, 0.9)),
));
}
3. 在 Update 中更新:
pub fn update_health_ui(
health: Query<&Health, With<Player>>,
mut ui: Query<&mut Node, With<HealthBar>>,
) {
if let (Ok(health), Ok(mut node)) = (health.get_single(), ui.get_single_mut()) {
node.width = Val::Px(health.percentage() * 200.0);
}
}
详细的 UI 模式,包括定位、样式和文本更新,请参见 references/ui_development.md。
将功能分解为阶段:
阶段 1:基础 - 核心组件和基本系统 阶段 2:内容 - 添加实体并填充世界 阶段 3:打磨 - UI 改进和视觉效果 阶段 4:高级功能 - 复杂机制和 AI
1. 计划 → 2. 实现 → 3. 构建 → 4. 测试 → 5. 优化
↑ ↓
←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←
每个阶段应包含:
对于原型(7-100 个实体):
对于生产(100+ 个实体):
Query<&Component, Changed<Component>>Query<&A, (With<B>, Without<C>)> 而不是在循环中过滤关键错误及其解决方案记录在 references/common_pitfalls.md 中。主要陷阱包括:
main.rs 中注册系统get_many_mut 进行多次修改)Changed<T>if let Ok() 模式)在实现复杂功能之前,请查阅 references/common_pitfalls.md。
在实现多步骤功能时,使用计划-实施者子代理,结构如下:
Goal: [一句话描述最终状态]
Current State: [当前存在什么]
Requirements: [要构建的内容的编号列表]
Implementation Steps: [建议的方法]
Success Criteria: [如何验证其有效]
Notes: [重要上下文、边界情况、设计原则]
示例:
Implement Health System
Goal: 实现一个包含伤害、治疗和死亡机制的生命值系统。
Current State:
- 玩家实体存在
- 尚无生命值追踪
Requirements:
1. 创建具有当前/最大值的 Health 组件
2. 创建用于造成伤害的 DamageEvent
3. 创建处理伤害事件的系统
4. 添加生命值降至 0 时的死亡检测
5. 添加视觉生命条 UI
Implementation Steps:
1. 在 src/components/properties.rs 中创建 Health 组件
2. 在 src/events.rs 中创建 DamageEvent
3. 在 src/systems/combat.rs 中创建 process_damage 系统
4. 创建 check_death 系统
5. 在 src/systems/ui/health_bar.rs 中创建生命条 UI
6. 在 main.rs 中以正确的顺序注册所有系统
Success Criteria:
- 玩家生成时带有 Health 组件
- 伤害事件会减少生命值
- 生命值变化时生命条会更新
- 生命值降至 0 时实体被销毁
- 代码编译无错误
关于推荐的文件组织、模块结构和组件文件模式的详细信息,请参见 references/project_structure.md。
此技能包含详细的参考文档:
references/bevy_specific_tips.md - 从这里开始: 注册表示例、插件结构、构建优化、版本管理、ECS 的领域驱动设计references/ecs_patterns.md - 组件设计模式、查询模式和常见的 ECS 设计模式(派生、状态机、阈值/触发器、事件驱动、初始化)references/ui_development.md - Bevy UI 层次结构、组件模式、布局技巧、定位、样式和文本更新references/common_pitfalls.md - 常见错误及其解决方案(系统注册、借用冲突、变更检测、系统排序、实体查询、资产句柄)references/project_structure.md - 推荐的文件组织、模块结构、组件文件模式和变更检测根据需要加载这些参考资料,以指导实现决策。
Bevy 文档:
~/.cargo/registry/... 中)ECS 设计原则:
记住: 以数据(组件)和转换(系统)的方式思考,而不是对象和方法。始终查阅注册表示例,并在深入实现之前设计好数据模型。这是有效进行 Bevy 开发的关键。
每周安装次数
64
代码仓库
GitHub 星标
38
首次出现
2026年1月24日
安全审计
安装于
opencode59
codex59
gemini-cli55
github-copilot52
amp49
kimi-cli49
A specialized skill for developing games and applications using the Bevy game engine, based on real-world experience building complex Bevy projects.
Invoke this skill when:
If working with Bevy 0.17 , be aware of significant API changes:
MeshMaterial3d<T> (not Handle<T>)commands.trigger(), add_observer())Seereferences/bevy_specific_tips.md for complete Bevy 0.17 migration guide and examples.
The registry examples are your bible. Always check them before implementing new features.
Location:
~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy-0.17.1/examples
There are MANY examples covering all aspects of Bevy development. Review relevant examples to understand best practices and working patterns.
Break your app into discrete modules using plugins. This improves organization and makes code discoverable.
pub struct CombatPlugin;
impl Plugin for CombatPlugin {
fn build(&self, app: &mut App) {
app
.add_event::<DamageEvent>()
.add_systems(Update, (process_damage, check_death));
}
}
See references/bevy_specific_tips.md for detailed plugin patterns and examples.
Pure ECS demands careful data modeling. It's hard to search a massive list of systems in one file!
Before implementing:
See references/bevy_specific_tips.md for domain-driven design guidance.
Bevy is an Entity Component System (ECS) engine. Always think in terms of data (components) and transformations (systems), not objects and methods.
Separation of Concerns:
Keep components focused:
// ✅ GOOD: Small, focused components
#[derive(Component)]
pub struct Health { pub current: f32, pub max: f32 }
#[derive(Component)]
pub struct Armor { pub defense: f32 }
// ❌ BAD: Monolithic component
#[derive(Component)]
pub struct CombatStats {
pub health: f32,
pub armor: f32,
pub strength: f32,
// ... wastes memory for entities that only have some stats
}
Add helper methods via impl blocks:
impl Health {
pub fn is_alive(&self) -> bool {
self.current > 0.0
}
pub fn percentage(&self) -> f32 {
self.current / self.max
}
}
For detailed component patterns, see references/ecs_patterns.md.
Order systems by dependencies:
.add_systems(
Update,
(
// 1. Input processing
handle_input,
// 2. State changes
process_events,
update_state,
// 3. Derive properties from state
calculate_derived_values,
// 4. Visual updates
update_materials,
update_animations,
// 5. UI updates (must run last)
update_ui_displays,
),
)
Use change detection to optimize:
// Only process entities where Health changed
pub fn update_health_bar(
query: Query<(&Health, &mut HealthBar), Changed<Health>>,
) {
for (health, mut bar) in query.iter_mut() {
bar.width = health.percentage() * 100.0;
}
}
For detailed query patterns and system design, see references/ecs_patterns.md.
Development (faster iteration):
cargo build --features bevy/dynamic_linking
Quick Check:
cargo check
Release (production):
cargo build --release
DO NOT delete target binaries freely! Bevy takes minutes to rebuild from scratch.
cargo clean unless absolutely necessarySee references/bevy_specific_tips.md for detailed build optimization and version management.
cargo checkcargo check then cargo build --features bevy/dynamic_linkingValidation points - Let the user test at these milestones:
Bevy uses a flexbox-like layout system. Follow the marker component pattern:
1. Create marker components:
#[derive(Component)]
pub struct HealthBar;
#[derive(Component)]
pub struct ScoreDisplay;
2. Setup in Startup:
pub fn setup_ui(mut commands: Commands) {
commands.spawn((
HealthBar,
Node {
position_type: PositionType::Absolute,
left: Val::Px(10.0),
top: Val::Px(10.0),
width: Val::Px(200.0),
height: Val::Px(20.0),
..default()
},
BackgroundColor(Color::srgba(0.8, 0.2, 0.2, 0.9)),
));
}
3. Update in Update:
pub fn update_health_ui(
health: Query<&Health, With<Player>>,
mut ui: Query<&mut Node, With<HealthBar>>,
) {
if let (Ok(health), Ok(mut node)) = (health.get_single(), ui.get_single_mut()) {
node.width = Val::Px(health.percentage() * 200.0);
}
}
For detailed UI patterns including positioning, styling, and text updates, see references/ui_development.md.
Break features into phases:
Phase 1: Foundation - Core components and basic systems Phase 2: Content - Add entities and populate world Phase 3: Polish - UI improvements and visual effects Phase 4: Advanced Features - Complex mechanics and AI
1. Plan → 2. Implement → 3. Build → 4. Test → 5. Refine
↑ ↓
←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←
Each phase should have:
For prototypes (7-100 entities):
For production (100+ entities):
Query<&Component, Changed<Component>>Query<&A, (With<B>, Without<C>)> instead of filtering in loopsCritical mistakes and their solutions are documented inreferences/common_pitfalls.md. Key pitfalls include:
main.rsget_many_mut for multiple mutations)Changed<T> for expensive operationsif let Ok() pattern)Review references/common_pitfalls.md before implementing complex features.
When implementing multi-step features, use the plan-implementer subagent with this structure:
Goal: [One sentence describing end state]
Current State: [What exists now]
Requirements: [Numbered list of what to build]
Implementation Steps: [Suggested approach]
Success Criteria: [How to verify it works]
Notes: [Important context, edge cases, design principles]
Example:
Implement Health System
Goal: Implement a health system with damage, healing, and death mechanics.
Current State:
- Player entity exists
- No health tracking yet
Requirements:
1. Create Health component with current/max values
2. Create DamageEvent for dealing damage
3. Create system to process damage events
4. Add death detection when health reaches 0
5. Add visual health bar UI
Implementation Steps:
1. Create Health component in src/components/properties.rs
2. Create DamageEvent in src/events.rs
3. Create process_damage system in src/systems/combat.rs
4. Create check_death system
5. Create health bar UI in src/systems/ui/health_bar.rs
6. Register all systems in main.rs in correct order
Success Criteria:
- Player spawns with Health component
- Damage events reduce health
- Health bar updates when health changes
- Entity despawns when health reaches 0
- Code compiles without errors
For details on recommended file organization, module structure, and component file patterns, see references/project_structure.md.
This skill includes detailed reference documentation:
references/bevy_specific_tips.md - START HERE: Registry examples, plugin structure, build optimization, version management, domain-driven design for ECSreferences/ecs_patterns.md - Component design patterns, query patterns, and common ECS design patterns (Derivation, State Machine, Threshold/Trigger, Event-Driven, Initialization)references/ui_development.md - Bevy UI hierarchy, component patterns, layout tips, positioning, styling, and text updatesreferences/common_pitfalls.md - Common mistakes and their solutions (system registration, borrowing conflicts, change detection, system ordering, entity queries, asset handles)references/project_structure.md - Recommended file organization, module structure, component file patterns, and change detectionLoad these references as needed to inform implementation decisions.
Bevy Documentation:
~/.cargo/registry/...)ECS Design Principles:
Remember: Think in terms of data (components) and transformations (systems), not objects and methods. Always consult registry examples and design your data model before diving into implementation. This is the key to effective Bevy development.
Weekly Installs
64
Repository
GitHub Stars
38
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykPass
Installed on
opencode59
codex59
gemini-cli55
github-copilot52
amp49
kimi-cli49
Laravel架构模式指南:生产级开发模式与最佳实践
1,100 周安装