public override void Update(GameTime gameTime) { while (!imageQueue.IsEmpty) { Tuple <bool, ImageModel> queued; if (imageQueue.TryDequeue(out queued)) { if (queued.Item1) { imageModels.Add(queued.Item2); } else { imageModels.Remove(queued.Item2); if (queued.Item2.BoundBox != null) { queued.Item2.BoundBox.Dispose(); } } } } foreach (ImageModel model in imageModels) { if (model.AnimationOn) { if (updateAnimation(gameTime, model) && OnAnimationDone != null) { OnAnimationDone.Invoke(this, model); } } } }
public void Draw(SpriteBatch spriteBatch, Vector2 objectPosition) { var(info, sprite) = spriteList.First(x => x.Key.Act == currentAction); var isAnimationDone = currentFrame >= info.FrameCount; if (isAnimationDone) { currentFrame = 0; currentAction = Act.Nop; OnAnimationDone?.Invoke(); } var spriteWidth = sprite.Width / info.FrameCount; var currentWindowX = currentFrame * spriteWidth; var currentWindowWidth = (int)Constants.WorldCellWidth * (isAnimationDone? 1 : 2); var window = new Rectangle(currentWindowX, 0, currentWindowWidth, (int)Constants.WorldCellHeight); spriteBatch.Draw( sprite, CalculatePosition(objectPosition, spriteWidth), window, Color.White); }