private void RenderLevel()
        {
            if (Level == null)
            {
                return;
            }

            //var canvas = new DrawingContextCanvas(drawingContext, ActualWidth, ActualHeight);
            int       screen_width  = Level.Width * block_width;
            int       screen_height = Level.Height * block_height;
            const int bpp           = 3;
            var       pixels        = new byte[bpp * screen_width * screen_height];
            var       canvas        = new Bgr24Canvas(pixels, bpp * screen_width, screen_width, screen_height);

            for (int y = 0; y < Level.Height; y++)
            {
                for (int x = 0; x < Level.Width; x++)
                {
                    int    b = Level.GetTile(x, y);
                    Sprite sprite;
                    if (block_map.TryGetValue(b, out sprite))
                    {
                        sprite.Draw(canvas, x * block_width, y * block_height);
                    }
                }
            }

            var bmp = new WriteableBitmap(screen_width, screen_height, 96, 96, PixelFormats.Bgr24, null);

            bmp.Lock();
            bmp.WritePixels(new Int32Rect(0, 0, screen_width, screen_height), pixels, bpp * screen_width, 0);
            bmp.Unlock();

            rendered_level = bmp;
        }
Beispiel #2
0
        private void UpdateSprite()
        {
            int width  = Sprite.PixelWidth;
            int height = Sprite.PixelHeight;
            int pitch  = width * 3;

            byte[] pixels = new byte[pitch * height];
            var    canvas = new Bgr24Canvas(pixels, pitch, width, height);

            Sprite.Draw(canvas, 0, 0);

            var bmp = new WriteableBitmap(Sprite.PixelWidth, Sprite.PixelHeight, 96, 96, PixelFormats.Bgr24, null);

            bmp.Lock();
            bmp.WritePixels(new Int32Rect(0, 0, width, height), pixels, pitch, 0);
            bmp.Unlock();

            image_source = bmp;
        }