void Update() { float t = 0; if (animating) { animationProgress += Time.deltaTime; t = animationProgress; } rotationOffset += SpeedAnim.Evaluate(t) * Time.deltaTime; float radius = RadiusAnim.Evaluate(t); float scale = SizeAnim.Evaluate(t); for (int i = 0; i < transforms.Count; i++) { float theta = Mathf.PI * 2 / transforms.Count * i + rotationOffset; transforms[i].localScale = new Vector2(scale, scale); Vector2 targetPosition = new Vector2(Mathf.Cos(theta) * radius, Mathf.Sin(theta) * radius); transforms[i].localPosition = Vector2.Lerp(transforms[i].localPosition, targetPosition, 1 - Mathf.Exp(-MovementSharpness * Time.deltaTime)); } if (animating && animationProgress >= AnimationLength) { OnAnimationComplete?.Invoke(); animating = false; animationProgress = 0; } }
public void Update(GameTime gameTime) { if (State != AnimationState.Playing) { return; } CurrentTime += (float)gameTime.ElapsedGameTime.TotalSeconds; int frameTime = (int)(CurrentTime * CurrentAnimation.FPS); int animationLenght = CurrentAnimation.Frames.Length; if (frameTime >= animationLenght) { var animation = CurrentAnimation; if (CurrentAnimation.IsLooping) { CurrentTime %= (animationLenght / animation.FPS); FrameIndex = animation.Frames[(int)(CurrentTime * animation.FPS)]; } else { FrameIndex = animation.Frames[animationLenght - 1]; Stop(); OnAnimationComplete?.Invoke(this, new AnimationEventArgs(animation, CurrentTime)); } } else { FrameIndex = CurrentAnimation.Frames[frameTime]; } }
public void Update(GameTime gameTime) { if (Frames.Count == 0) { return; } _currentElapsedTime += gameTime.ElapsedGameTime.Milliseconds; if (_currentElapsedTime >= Frames[_currentFrame].Duration) { _currentElapsedTime = 0; var nextFrame = _currentFrame + 1; if (nextFrame >= Frames.Count) { if (Looping) { _currentFrame = 0; } else { if (!CompleteAnimation) { // stay stuck on last frame CompleteAnimation = true; OnAnimationComplete?.Invoke(this); } } } else { _currentFrame = nextFrame; } } }
public void NextFrame() { if (animationDirection != 0) { animationcount++; if (animationcount >= animationSpeed) { if (animationDirection > 0) { if (currentFrame >= stopFrame) { if (animateOnce) { currentFrame = stopFrame; OnAnimationComplete?.Invoke(id); } else { currentFrame = startFrame; } } else { currentFrame++; } } if (animationDirection < 0) { if (currentFrame <= startFrame) { if (animateOnce) { currentFrame = startFrame; OnAnimationComplete?.Invoke(id); } else { currentFrame = stopFrame; } } else { currentFrame--; } } animationcount = 0; } } if (movementEnabled) { movementcount++; if (movementcount >= movementSpeed) { SetPosition(Convert.ToInt32(xPos + movementDistance * Math.Cos(radianAngle)), Convert.ToInt32(yPos + movementDistance * Math.Sin(radianAngle))); movementcount = 0; } } }
internal void OnComplete() { OnAnimationComplete?.Invoke(this, new EventArgs()); }
protected override void OnComplete(object sender, EventArgs e) { OnAnimationComplete?.Invoke(); base.OnComplete(sender, e); }