pub struct AnimationController {
pub states: HashMap<String, AnimationState>,
pub transitions: Vec<AnimationTransition>,
pub parameters: HashMap<String, AnimParam>,
pub current_state: String,
pub transition_progress: Option<TransitionProgress>,
}Expand description
ECS component that manages animation state machine logic.
The controller holds a set of named states, transitions between them,
and parameters that drive transition conditions. Pair with a
SpriteAnimator component
and the update_animation_controllers
system.
§Example
use goud_engine::ecs::components::sprite_animator::AnimationClip;
use goud_engine::ecs::components::animation_controller::{
AnimationController, TransitionCondition,
};
use goud_engine::core::math::Rect;
let idle_clip = AnimationClip::new(
vec![Rect::new(0.0, 0.0, 32.0, 32.0)],
0.1,
);
let run_clip = AnimationClip::new(
vec![Rect::new(32.0, 0.0, 32.0, 32.0)],
0.1,
);
let controller = AnimationController::new("idle")
.with_state("idle", idle_clip)
.with_state("run", run_clip)
.with_transition(
"idle", "run", 0.1,
vec![TransitionCondition::BoolEquals {
param: "running".to_string(),
value: true,
}],
);
assert_eq!(controller.current_state_name(), "idle");Fields§
§states: HashMap<String, AnimationState>Named animation states.
transitions: Vec<AnimationTransition>Transitions between states.
parameters: HashMap<String, AnimParam>Parameters driving transition conditions.
current_state: StringName of the currently active state.
transition_progress: Option<TransitionProgress>Active transition, if any.
Implementations§
Source§impl AnimationController
impl AnimationController
Sourcepub fn new(initial_state: &str) -> AnimationController
pub fn new(initial_state: &str) -> AnimationController
Creates a new controller with the given initial state name.
The controller starts with no states, transitions, or parameters. Use the builder methods to add them.
Precondition: initial_state should name a state that will be
registered via with_state before the controller
is used. If the state is never added, lookups such as
current_clip will return None.
Sourcepub fn with_state(self, name: &str, clip: AnimationClip) -> AnimationController
pub fn with_state(self, name: &str, clip: AnimationClip) -> AnimationController
Adds an animation state with the given name and clip (builder pattern).
Sourcepub fn with_transition(
self,
from: &str,
to: &str,
blend_duration: f32,
conditions: Vec<TransitionCondition>,
) -> AnimationController
pub fn with_transition( self, from: &str, to: &str, blend_duration: f32, conditions: Vec<TransitionCondition>, ) -> AnimationController
Adds a transition between two states (builder pattern).
Sourcepub fn get_param(&self, name: &str) -> Option<&AnimParam>
pub fn get_param(&self, name: &str) -> Option<&AnimParam>
Returns a reference to the parameter with the given name, if it exists.
Sourcepub fn current_state_name(&self) -> &str
pub fn current_state_name(&self) -> &str
Returns the name of the current state.
Sourcepub fn current_clip(&self) -> Option<&AnimationClip>
pub fn current_clip(&self) -> Option<&AnimationClip>
Returns a reference to the current state’s animation clip, if the current state exists in the states map.
Trait Implementations§
Source§impl Clone for AnimationController
impl Clone for AnimationController
Source§fn clone(&self) -> AnimationController
fn clone(&self) -> AnimationController
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AnimationController
impl Debug for AnimationController
impl Component for AnimationController
Auto Trait Implementations§
impl Freeze for AnimationController
impl RefUnwindSafe for AnimationController
impl Send for AnimationController
impl Sync for AnimationController
impl Unpin for AnimationController
impl UnsafeUnpin for AnimationController
impl UnwindSafe for AnimationController
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more