3个版本 (破坏性)
0.3.0 | 2022年8月23日 |
---|---|
0.2.0 | 2022年5月13日 |
0.1.0 | 2022年3月12日 |
#1906 in 游戏开发
26KB
331 行
统计条
一个简单的库,专门用于在精灵上方绘制统计条以显示其健康值或其他信息。
唯一目标是成为一个易于使用的crate,您可以将其添加到任何项目中,并在不到十分钟内获得统计条。
- 针对Bevy 0.8
- 仅支持2D。
- 永远不会非常可定制或复杂。
- 目前只支持居中水平条。下一版本将支持任意方向等。
基本教程
将StatBarsPlugin添加到您的应用程序中,然后您可以像这样生成统计条
commands
.spawn_bundle((
// color of the statbar (required)
StatBarColor(Color::GREEN),
// color of the empty part of the statbar (optional)
StatBarEmptyColor(Color::BLACK),
// color and thickness of the border (optional)
StatBarBorder { color: Color::DARK_GRAY, thickness: 3.0 },
// initial value (0.0 is empty, 1.0 is full) (required)
StatBarValue(1.0),
// length and thickness of the bar (required)
StatBarSize { full_length: 50.0, thickness: 6.0 },
// entity the statbar tracks (required)
StatBarSubject(player_entity),
// position relative to the subject entity (40 units above in this case) (optional)
StatBarPosition(40.0 * Vec2::Y),
// takes a |&Component| -> f32 closure, which is called each tick with the
// respective component of the subject entity.
// returned f32 value is used to update StatBarValue
// (optional, can leave out and just update StatBarValue manually)
component_observer(|hp: &Hp| hp.current as f32 / hp.max as f32)
));
并且它们应该可以正常工作。
注意
-
统计条是一个单个实体。它使用bevy精灵渲染器进行绘制,但不创建任何中间精灵实体。
-
默认情况下,统计条具有950的z_depth,您可以使用StatBarZDepth组件自行设置。
-
当主题被销毁时,条将自动销毁。
-
不使用内置的父子转换传播,因为大多数情况下游戏不希望其指示元素与跟踪的精灵旋转或缩放。
-
未进行优化,不使用更改检测等。但极不可能成为严重的性能瓶颈,除非您一次生成10,000个统计条或其他类似操作。
-
您可以有一个以上的统计条跟踪主题实体。只需确保每个都具有不同的
StatBarPosition
,这样它们就不会全部重叠。 -
ComponentObserver实现相对较慢,如果您有很多状态条,您可能希望直接更新StatusBarValue。组件观察器的优点是分离。您不需要修改现有的实体和系统即可使用它们。
在/example文件夹中有一个完整的示例。
任何反馈/改进建议/代码提交都将非常受欢迎。
依赖项
~42–56MB
~805K SLoC