Example #1
0
        public void Draw(Graphics gfx, TileMap map)
        {
            if (map.Sprite != null)
            {
                if (tiles == null)
                {
                    tiles = BitmapExtensions.CreateBitmap(map.Width, map.Height);
                    tiles.MakeTransparent();
                    Graphics mgfx = Graphics.FromImage(tiles);
                    mgfx.Clear(Color.Transparent);
                    mgfx.Clip = new Region(new Rectangle(new Point(), new Size(map.Width, map.Height)));
                    int x = 0;
                    int y = 0;
                    foreach (int tile in map.Tiles)
                    {
                        mgfx.DrawImage(map.Image(tile), new RectangleF(x * map.Sprite.Width, y * map.Sprite.Height, map.Sprite.Width, map.Sprite.Height), new RectangleF(0, 0, map.Sprite.Width, map.Sprite.Height), GraphicsUnit.Pixel);
                        x++;
                        if (x >= map.Columns)
                        {
                            x = 0;
                            y++;
                        }
                    }

                    mgfx.DrawRectangle(Pens.Black, 0, 0, map.Width - 1, map.Height - 1);
                }

                gfx.DrawImage(tiles, new RectangleF(0, 0, tiles.Width, tiles.Height), new RectangleF(0, 0, tiles.Width, tiles.Height), GraphicsUnit.Pixel);
            }
        }
Example #2
0
        public void Init(int width, int height, int xScale, int yScale)
        {
            Bitmap[] buffer = new Bitmap[] { BitmapExtensions.CreateBitmap(width, height), BitmapExtensions.CreateBitmap(width, height) };
            buffer[0].MakeTransparent();
            buffer[1].MakeTransparent();
            Bitmap[] overlay = new Bitmap[] { BitmapExtensions.CreateBitmap(width * xScale, height * yScale), BitmapExtensions.CreateBitmap(width * xScale, height * yScale) };
            overlay[0].MakeTransparent();
            overlay[1].MakeTransparent();

            sbuffer  = new SystemBitmap[] { new SystemBitmap(buffer[0]), new SystemBitmap(buffer[1]) };
            soverlay = new SystemBitmap[] { new SystemBitmap(overlay[0]), new SystemBitmap(overlay[1]) };
        }
Example #3
0
        public Sprite(string name, Stream sbmp, int x, int y)
        {
            Name = name;
            Bitmap bmp = BitmapExtensions.CreateBitmap(sbmp);

            this.image = new[] { bmp };
            hSubImages = 1;
            vSubImages = 1;
            Width      = bmp.Width;
            Height     = bmp.Height;
            X          = x;
            Y          = y;
            Sprites.Add(name, this);
        }
Example #4
0
        private void SetupSubImages(Bitmap bmp, int tileWidth, int tileHeight)
        {
            Width  = tileWidth;
            Height = tileHeight;

            hSubImages = (bmp.Width / Width);
            vSubImages = (bmp.Height / Height);

            image = new Bitmap[hSubImages * vSubImages];

            for (int j = 0; j < vSubImages; j++)
            {
                for (int i = 0; i < hSubImages; i++)
                {
                    image[i + j * hSubImages] = BitmapExtensions.CreateBitmap(Width, Height);
                    using (Graphics gfx = Graphics.FromImage(image[i + j * hSubImages]))
                    {
                        gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                        gfx.DrawImage(bmp, new RectangleF(0, 0, Width, Height), new RectangleF(i * Width, j * Height, Width, Height), GraphicsUnit.Pixel);
                    }
                }
            }
        }