2个版本 (1个稳定版)
1.0.0 | 2022年4月15日 |
---|---|
0.0.0 | 2022年3月26日 |
#1868 在 游戏开发
1MB
553 行
Bevy UI Animation
Bevy UI的GSAP类似动画插件。
🌌 特性
- ✅ 动画NodeBundle, ImageBundle, TextBundle, ButtonBundle
- 🚧 时间轴支持
- 🚧 Bevy事件支持
🔮 使用方法
要使用此插件,第一步是在你的 Cargo.toml
中添加依赖项
[dependencies]
bevy_ui_animation = "1.0.0"
将 AnimationPlugin
添加到你的 main.rs
use bevy::prelude::*;
use bevy_ui_animation::*;
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(AnimationPlugin)
.run();
动画一个组件
use bevy::prelude::*;
use bevy_ui_animation::*;
fn setup(mut commands: Commands) {
commands.spawn_bundle(UiCameraBundle::default());
commands
.spawn_bundle(NodeBundle {
style: Style {
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
..Default::default()
},
color: UiColor(Color::BLUE),
transform: Transform::default(),
..Default::default()
})
.insert(Animation::new(Vars {
style: Some(Style {
size: Size::new(Val::Percent(50.0), Val::Percent(50.0)),
..Default::default()
}),
color: Some(UiColor(Color::RED)),
transform: Some(Transform::from_rotation(Quat::from_rotation_z(
180_f32.to_radians(),
))),
duration: 2.0,
ease: Ease::ExpoOut,
repeat: true,
yoyo: true,
..Default::default()
}));
}
预览
你可以通过以下方式直接运行此示例
cargo run --example all --features="bevy/bevy_winit"
✳️ 变量
字段 | 类型 | 默认值 | 描述 |
---|---|---|---|
style | Option<样式> |
None |
包含要动画的目标字段的Bevy Style组件。 |
color | Option<UiColor> |
None |
包含要动画的目标字段的Bevy UiColor组件。 |
transform | Option<Transform> |
None |
包含要动画的目标字段的Bevy Transform组件。 |
transform_rotation | Option<TransformRotation> |
None |
一个结构体,用于围绕给定的固定轴旋转Bevy Transform组件。 |
text_color | Option<TextColor> |
None |
一个结构体,用于线性插值Bevy Text组件的颜色。 |
delay | f32 |
0.0 |
动画开始前的延迟量(以秒为单位)。 |
duration | f32 |
0.5 |
动画的持续时间(以秒为单位)。 |
ease | Ease |
ExpoOut |
控制动画变化速率的缓动函数。 |
repeat | bool |
false |
如果 true ,则动画将不断重复。 |
yoyo | bool |
false |
如果 true ,则动画完成后将按相反方向运行。 |
paused | bool |
false |
如果 true ,则动画将在创建时立即暂停。 |
📜 可动画组件
名称 | 字段 |
---|---|
样式 | position |
margin | |
padding | |
border | |
size | |
UiColor | color |
Transform | translation |
rotation | |
scale | |
Text | TextStyle::color |
📈 缓动
名称 | 0% | 50% | 100% |
---|---|---|---|
BackIn | 0.0 |
-0.375 |
1.0 |
BackInOut | 0.0 |
0.499 |
1.0 |
BackOut | -1.19e-7 |
1.375 |
1.0 |
BounceIn | 0.0 |
0.281 |
1.0 |
BounceInOut | 0.0 |
0.5 |
1.0 |
BounceOut | 0.0 |
0.718 |
1.0 |
ElasticIn | 0.0 |
-4.29e-8 |
2.74e-6 |
ElasticInOut | 0.0 |
0.099 |
1.0 |
ElasticOut | 0.099 |
1.0 |
1.0 |
ExpoIn | 0.0 |
0.031 |
1.0 |
ExpoInOut | 0.0 |
0.5 |
1.0 |
ExpoOut | 0.0 |
0.968 |
1.0 |
Linear | 0.0 |
0.5 |
1.0 |
PowerIn | 0.0 |
0.25 |
1.0 |
PowerInOut | 0.0 |
0.5 |
1.0 |
PowerOut | 0.0 |
0.75 |
1.0 |
❇️ 兼容性
bevy_ui_animation |
bevy |
---|---|
1.0 |
0.6 |
🙏 感谢
- @djeedai for bevy_tweening
- @mockersf for bevy_easings
- @Piston开发者们,有关interpolation
🖋 作者
miZyind mizyind@gmail.com
📇 许可证
在MIT 许可证下授权。
依赖项
~38–53MB
~754K SLoC