/// <summary> /// Update method for objects that do not move. /// </summary> public void Update() { FindHighestPriorityAnimation(); if (_frameTimer.TimeElapsedInMilliSeconds > _currentAnimationData.Speed) { _frameTimer.Reset(); _currentFrame++; if (_currentFrame >= _currentAnimationData.FrameCount) { AnimationEnded?.Invoke(); // Send notice that animation has ended. if (!_currentAnimationData.IsRepeating) { _currentFrame = _currentAnimationData.FrameCount - 1; } else { _currentFrame = 0; } } FrameChanged?.Invoke(new FrameArgs(_currentFrame)); } _sourceRectangle.X = _currentFrame * _currentAnimationData.Width; }
public void NextFrame() { if (++CurrentFrameId >= Length || CurrentFrameId > LoopEnd) { if (Looping) { CurrentFrameId = LoopStart; } else { AnimationEnded?.Invoke(); CurrentFrameId = Length - 1; } } }
/// <summary> /// Advances the time position and draws the current frame of the animation. /// </summary> public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Vector2 position, SpriteEffects spriteEffects) { if (Animation == null) { throw new NotSupportedException("No animation is currently playing."); } // Process passing time. time += (float)gameTime.ElapsedGameTime.TotalSeconds; while (time > Animation.FrameTime) { time -= Animation.FrameTime; // Advance the frame index; looping or clamping as appropriate. if (Animation.IsStill != true) { if (Animation.IsLooping) { frameIndex = (frameIndex + 1) % Animation.FrameCount; /* USED TO SKIP FIRST FRAME WHILE MOVING * if(frameIndex == 0) * { * frameIndex++; * } */ } else { if ((frameIndex + 1) > Animation.FrameCount - 1) { AnimationEnded?.Invoke(this, new EventArgs()); } frameIndex = Math.Min(frameIndex + 1, Animation.FrameCount - 1); } } else { frameIndex = 0; } } // Calculate the source rectangle of the current frame. Rectangle source = new Rectangle(FrameIndex * Animation.Texture.Height, 0, Animation.Texture.Height, Animation.Texture.Height); // Draw the current frame. spriteBatch.Draw(Animation.Texture, position, source, DrawColor, Rotation, Origin, Scale, spriteEffects, 0.0f); }
/// <summary> /// Update the aniamtion, timers and fire events. /// </summary> /// <param name="entity"></param> public void Update(Entity entity) { //SpeedParticle speed = new SpeedParticle(texture, drawRectangle.X, drawRectangle.Y, sourceRectangle, entity.IsFacingRight); //GameWorld.ParticleSystem.Add(speed); FindHighestPriorityAnimation(); UpdatePositionOnly(entity); if (_currentName == "walk" || _currentName == "run") { // y = 1020/(x + 1) - 20 _currentAnimationData.Speed = (int)(-20 + 500f / (Math.Abs(entity.GetVelocity().X) + 1)); } if (_currentName == "climb") { _currentAnimationData.Speed = (int)(-20 + 500f / (Math.Abs(entity.GetVelocity().Y) + 1)); if (Math.Abs(entity.GetVelocity().Y) < .1f) { _currentAnimationData.Speed = Int32.MaxValue; } } if (_frameTimer.TimeElapsedInMilliSeconds > _currentAnimationData.Speed) { _frameTimer.Reset(); _currentFrame++; if (_currentFrame >= _currentAnimationData.FrameCount) { AnimationEnded?.Invoke(); // Send notice that animation has ended. if (!_currentAnimationData.IsRepeating) { _currentFrame = _currentAnimationData.FrameCount - 1; } else { _currentFrame = 0; } } FrameChanged?.Invoke(new FrameArgs(_currentFrame)); } _sourceRectangle.X = _currentFrame * _currentAnimationData.Width; }
public void Step() { //this is under a timer an needs AgentAnimation animation = this.currentAnimation; var frame = this.currentFrame; if (animation == null) { return; } var newFrameIndex = Math.Min(this.GetNextAnimationFrame(), animation.Frames.Count - 1); var frameChanged = frame != null && this.currentFrameIndex != newFrameIndex; this.currentFrameIndex = newFrameIndex; // always switch frame data, unless we're at the last frame of an animation with a useExitBranching flag. if (!(this.IsAtLastFrame() && animation.UseExitBranching)) { currentFrame = frame = animation.Frames[this.currentFrameIndex]; } if (frame.Duration > 0) { NeedsRefresh?.Invoke(this, EventArgs.Empty); agent.PlaySound(currentFrame?.Sound); aTimer.Interval = frame.Duration; aTimer.Start(); } if (frameChanged && this.IsAtLastFrame()) { _started = false; if (animation.UseExitBranching && !this._exiting) { AnimationEnded?.Invoke(this, new AnimationStateEventArgs(currentAnimationName, AnimationStates.Waiting)); } else { AnimationEnded?.Invoke(this, new AnimationStateEventArgs(currentAnimationName, AnimationStates.Exited)); } } }
private Transition GetNextTransition() { if (_currentKey + 1 >= _keys.Length) { AnimationIterationEnded?.Invoke(); if (--_iterations <= 0) { AnimationEnded?.Invoke(); return(null); } _currentKey = 0; } Transition transition = GetTransition(_keys[_currentKey], _keys[++_currentKey], _transitionDuration); transition.Process += Process; transition.TransitionEnded += TransitionEnded; transition.TransitionPaused += TransitionPaused; return(transition); }
public void EndLevelAnim() { Transform transform = Player.Instance.transform; Player.Instance.IsNotMoving = true; Player.Instance.IsNotShooting = true; Player.CollideWithDamageDealers = false; //transform.position = new Vector3(0.0f, -ParallaxCamera.ParallaxSize.y / 2 - 1, 0.0f); //yield return transform.DOMove(transform.position.With(y:transform.position.y - 2f), 0.5f) // .SetEase<Tween>(Ease.OutSine) // .WaitForCompletion(); transform.DOMove(transform.position.With(y: ParallaxCamera.CameraBoundary.yMax + 2f), 2f) .SetEase <Tween>(Ease.InBack) .OnComplete(() => { BulletPoolsContainer.Instance.ClearAllBullets(); AnimationEnded.Invoke(); }); }
protected void EndAnimation(string type) { AnimationEnded?.Invoke(this, new AnimationEventArgs(TargetObject, type)); }
protected void Stop() { AnimationEnded?.Invoke(this, new AnimationEndedArgs(PreviousChild, NewChild)); }
public void OnAnimationEnded() { AnimationEnded.Invoke(); }
private void ComplexAnim_AnimationEnded() { AnimationEnded?.Invoke(this); }
//call from animation event private void FadeEnded() { AnimationEnded?.Invoke(this, EventArgs.Empty); }
private void OnEndAnimation() { AnimationEnded?.Invoke(this); }