Skip to content
Snippets Groups Projects
Commit f32c4a2a authored by Jerome Humbert's avatar Jerome Humbert
Browse files

Add tween started/ended callbacks

Implement some callbacks invoked when a tween anim starts or ends.
parent 5e3ed117
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -5,6 +5,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added
- Add user callbacks on tween started (`Tween::set_started`) and ended (`Tween::set_ended`).
- Implement `Default` for `AnimatorState` as `AnimatorState::Playing`.
- Added `Animator::with_state()` and `AssetAnimator::with_state()`, builder-like functions to override the default `AnimatorState`.
- Added `Tween::is_looping()` returning true for all but `TweeningType::Once`.
### Changed
- Moved tween duration out of the `TweeningType` enum, which combined with the removal of the "pause" feature in loops makes it a C-like enum.
### Removed
- Removed the "pause" feature in-between loops of `TweeningType::Loop` and `TweeningType::PingPong`, which can be replaced if needed with a sequence including a no-op tween of the desired duration. Removed `Tween::is_paused()`.
### Fixed ### Fixed
- Fix missing public export of `component_animator_system()` and `asset_animator_system()` preventing the animation of all but the built-in items. - Fix missing public export of `component_animator_system()` and `asset_animator_system()` preventing the animation of all but the built-in items.
......
This diff is collapsed.
...@@ -19,7 +19,7 @@ use crate::{Animator, AnimatorState, AssetAnimator}; ...@@ -19,7 +19,7 @@ use crate::{Animator, AnimatorState, AssetAnimator};
/// added manually by the application: /// added manually by the application:
/// - For components, add [`component_animator_system::<T>`] where `T: Component` /// - For components, add [`component_animator_system::<T>`] where `T: Component`
/// - For assets, add [`asset_animator_system::<T>`] where `T: Asset` /// - For assets, add [`asset_animator_system::<T>`] where `T: Asset`
/// ///
/// This plugin is entirely optional. If you want more control, you can instead add manually /// This plugin is entirely optional. If you want more control, you can instead add manually
/// the relevant systems for the exact set of components and assets actually animated. /// the relevant systems for the exact set of components and assets actually animated.
/// ///
...@@ -50,12 +50,19 @@ pub fn component_animator_system<T: Component>( ...@@ -50,12 +50,19 @@ pub fn component_animator_system<T: Component>(
mut query: Query<(&mut T, &mut Animator<T>)>, mut query: Query<(&mut T, &mut Animator<T>)>,
) { ) {
for (ref mut target, ref mut animator) in query.iter_mut() { for (ref mut target, ref mut animator) in query.iter_mut() {
let state_changed = animator.state != animator.prev_state;
animator.prev_state = animator.state;
if animator.state == AnimatorState::Paused { if animator.state == AnimatorState::Paused {
continue; if state_changed {
} for seq in &mut animator.tracks_mut().tracks {
// Play all tracks in parallel seq.stop();
for seq in &mut animator.tracks_mut().tracks { }
seq.tick(time.delta(), target); }
} else {
// Play all tracks in parallel
for seq in &mut animator.tracks_mut().tracks {
seq.tick(time.delta(), target);
}
} }
} }
} }
...@@ -69,10 +76,15 @@ pub fn asset_animator_system<T: Asset>( ...@@ -69,10 +76,15 @@ pub fn asset_animator_system<T: Asset>(
mut query: Query<&mut AssetAnimator<T>>, mut query: Query<&mut AssetAnimator<T>>,
) { ) {
for ref mut animator in query.iter_mut() { for ref mut animator in query.iter_mut() {
let state_changed = animator.state != animator.prev_state;
animator.prev_state = animator.state;
if animator.state == AnimatorState::Paused { if animator.state == AnimatorState::Paused {
continue; if state_changed {
} for seq in &mut animator.tracks_mut().tracks {
if let Some(target) = assets.get_mut(animator.handle()) { seq.stop();
}
}
} else if let Some(target) = assets.get_mut(animator.handle()) {
// Play all tracks in parallel // Play all tracks in parallel
for seq in &mut animator.tracks_mut().tracks { for seq in &mut animator.tracks_mut().tracks {
seq.tick(time.delta(), target); seq.tick(time.delta(), target);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment