Esempio n. 1
0
        private void OnPathChangedHandler()
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                ClearSprites();

                var drawing = new DrawingVisual();
                using (var context = drawing.RenderOpen())
                {
                    context.DrawEllipse(Brushes.YellowGreen, null,
                                        new Point(25, 25), 5, 5);
                }

                var source =
                    new RenderTargetBitmap(Constants.CellSize, Constants.CellSize, 96, 96, PixelFormats.Pbgra32);
                source.Render(drawing);

                foreach (var point in _ship.Path)
                {
                    var pathSprite = new DrawnObjectViewModel(source)
                    {
                        X = point.X * Constants.CellSize,
                        Y = point.Y * Constants.CellSize
                    };
                    _pathSprites.Add(pathSprite);
                    OnSpriteAdded?.Invoke(this, pathSprite);
                }
            });
        }
Esempio n. 2
0
        public void Add(Sprite sprite)
        {
            if (sprite == null)
            {
                throw new ArgumentNullException("sprite has null value!");
            }

            sprites.Add(sprite);

            OnSpriteAdded?.Invoke(this, new SpriteEventArgs(sprite));

            OnCollectionChanged?.Invoke(this, EventArgs.Empty);
        }