2 个版本
0.1.1 | 2020年1月9日 |
---|---|
0.1.0 | 2019年7月16日 |
#1408 在 算法 中
每月 23 次下载
8KB
183 行
easings-rs
这是一个非常简单的 easing 实现,可以在 https://easings.net/en 找到。目的是提供简单易用的功能,而不需要太多花哨的功能。
通过将以下内容放入 Cargo.toml
中的依赖项来安装
easings-rs = "0.1.0"
有一个单独的枚举,其中包含上述网站上文档中每个 easing 效果的一个变体,以及一个 Linear
easing。它们作为 <category><in/out/inout>
提供,例如 ElasticOut
或 SineInOut
。还有一个名为 ease
的导出函数,可以调用以获取百分比的 easing 值(0 到 1 之间的 f32
)。
假设你正在使用像 Amethyst 这样的游戏引擎,并且你在两个位置之间对对象进行 easing
#[derive(Component)]
pub struct EaseEffect {
pub duration_frames: u64,
pub start_frame: u64,
pub easing: Easing,
}
// ...
let frames_elapsed = time.frame_number() - ease_effect.start_frame;
let percent = frames_elapsed as f32 / ease_effect.duration_frames as f32;
let progress = ease(ease_effect.easing, percent);
*transform.translation_mut() = source + progress * (destination - source);