/// <summary> /// Sets current animation and starts it. /// </summary> /// <param name="name">Name of animation</param> public void SetAnimation(string name) { _currentAnimationName = name; CurrentAnimation = _animations[name]; CurrentAnimation.Start(); AnimationStarted?.Invoke(name); }
public FigureMovementAnimationComponent(Entity parent, Animation forward, Animation backward, Animation left, Animation right) : base(parent) { if (forward == null) throw new ArgumentNullException(nameof(forward)); AddAnimation(ForwardAnimation, forward); AddAnimation(BackwardAnimation, backward ?? forward); AddAnimation(LeftAnimation, left ?? forward); AddAnimation(RightAnimation, right ?? forward); }
/// <summary> /// Sets current animation and starts it. /// </summary> /// <param name="name">Name of animation</param> /// <param name="playReversed">Plays the animation backwards.</param> public void SetAnimation(string name, bool playReversed = false) { if (_currentAnimationName == name && CurrentAnimation != null) { if (CurrentAnimation.PlayReversed == playReversed) return; CurrentAnimation.Start(playReversed); } else { _currentAnimationName = name; CurrentAnimation = _animations[name]; CurrentAnimation.Start(playReversed); AnimationStarted?.Invoke(name); } }
/// <summary> /// Registeres new animation. /// </summary> /// <param name="name">name of animation</param> /// <param name="animation">Object</param> public void AddAnimation(string name, Animation animation) { _animations.Add(name, animation); }
/// <summary> /// Updates Animator. /// </summary> public void Update(GameTime gameTime) { if (CurrentAnimation == null) return; CurrentAnimation.Update(gameTime.GetSeconds()); if (CurrentAnimation.IsFinished) { if (CurrentAnimation.IsLoop) { CurrentAnimation.Start(); } else { AnimationFinished?.Invoke(_currentAnimationName, CurrentAnimation.PlayReversed); string newAnimation; if (_transitions.TryGetValue(_currentAnimationName, out newAnimation)) { SetAnimation(newAnimation); } else { CurrentAnimation = null; AnimatorFinished?.Invoke(); } } } }
public void Stop() { CurrentAnimation = null; }
public void AddAnimation(string animationName, Animation animation) { _animator.AddAnimation(animationName, animation); }
/// <summary> /// Updates Animator. /// </summary> /// <param name="elapsedSeconds">elapsed time seconds since last call.</param> public void Update(float elapsedSeconds) { if (CurrentAnimation == null) return; CurrentAnimation.Update(elapsedSeconds); if (CurrentAnimation.IsFinished) { AnimationFinished?.Invoke(_currentAnimationName); string newAnimation; if (_transitions.TryGetValue(_currentAnimationName, out newAnimation)) { SetAnimation(newAnimation); } else { CurrentAnimation = null; AnimatorFinished?.Invoke(); } } }