private async void AnimateTiles(AnimatedTilesCollection animatedTilesCollection, bool updateTiles) { bool hasTiles = animatedTilesCollection != null && animatedTilesCollection.Tiles != null && animatedTilesCollection.Tiles.Any(); if (hasTiles && animatedTilesCollection.Frames != null && animatedTilesCollection.Frames.Any()) { foreach (var frame in animatedTilesCollection.Frames) { var animationVisual = new DrawingVisual(); using (var drawingContext = animationVisual.RenderOpen()) { var image = frame.Image; var offsetX = Math.Max(0, (this.TileSize.Width - image.Width) / 2); var offsetY = Math.Max(0, (this.TileSize.Height - image.Height) / 2); foreach (var tilePoint in animatedTilesCollection.Tiles) { var boardPoint = this.GetBoardCoordinatesFromTilePoint(tilePoint); var drawRect = new Rect( boardPoint.X + offsetX, boardPoint.Y + offsetY, image.Width, image.Height); drawingContext.DrawImage(image, drawRect); } this.AddVisualChild(animationVisual); await Task.Delay((int)frame.Interval).ConfigureAwait(true); this.RemoveVisualChild(animationVisual); } } } if (updateTiles) { if (hasTiles) { this.proxy.Lock(); foreach (var tilePoint in animatedTilesCollection.Tiles) { this.DrawTile(tilePoint.X, tilePoint.Y); } this.proxy.Unlock(); } } else { this.DrawSelectedTiles(); } }
private async void AnimateTiles(AnimatedTilesCollection animatedTilesCollection, bool updateTiles) { bool hasTiles = animatedTilesCollection != null && animatedTilesCollection.Tiles != null && animatedTilesCollection.Tiles.Any(); if (hasTiles && animatedTilesCollection.Frames != null && animatedTilesCollection.Frames.Any()) { foreach (var frame in animatedTilesCollection.Frames) { var animationVisual = new DrawingVisual(); using (var drawingContext = animationVisual.RenderOpen()) { var image = frame.Image; var offsetX = Math.Max(0, (this.TileSize.Width - image.Width) / 2); var offsetY = Math.Max(0, (this.TileSize.Height - image.Height) / 2); foreach (var tilePoint in animatedTilesCollection.Tiles) { var boardPoint = this.GetBoardCoordinatesFromTilePoint(tilePoint); var drawRect = new Rect( boardPoint.X + offsetX, boardPoint.Y + offsetY, image.Width, image.Height); drawingContext.DrawImage(image, drawRect); } this.AddVisualChild(animationVisual); await Task.Delay((int)frame.Interval).ConfigureAwait(true); this.RemoveVisualChild(animationVisual); } } } if (updateTiles) { if (hasTiles) { this.DrawTiles(animatedTilesCollection.Tiles); } } else { this.DrawSelectedTiles(); } }