ARCed.Controls.MapEditorXnaPanel.CreateAutotile C# (CSharp) Метод

CreateAutotile() публичный Метод

Creates an internal texture used for blit operations from the autotile graphic.
public CreateAutotile ( string filename ) : Microsoft.Xna.Framework.Graphics.Texture2D[]
filename string Filename of the autotile graphic
Результат Microsoft.Xna.Framework.Graphics.Texture2D[]
        public Texture2D[] CreateAutotile(string filename)
        {
            const int w = Constants.TILESIZE;
            const int hw = Constants.TILESIZE / 2;
            var data = new Texture2D[48];
            var autotile = Cache.Autotile(filename);
            if (autotile == null)
                return data;
            int x, y, num, index, sx, sy;
            SysRect destRect, srcRect;
            for (var frame = 0; frame < (autotile.Width / 96); frame++)
            {
                using (var template = new Bitmap(256, 192))
                {
                    for (var lvl = 0; lvl < 6; lvl++)
                    {
                        for (var j = 0; j < 8; j++)
                        {
                            using (var g = Graphics.FromImage(template))
                            {
                                foreach (var number in _autoindex[8 * lvl + j])
                                {
                                    num = number - 1;
                                    x = 16 * (num % 6);
                                    y = 16 * (num / 6);
                                    srcRect = new SysRect(x + (frame * 96), y, hw, hw);
                                    destRect = new SysRect(w * j + x % w, w * lvl + y % w, hw, hw);
                                    g.DrawImage(autotile, destRect, srcRect, System.Drawing.GraphicsUnit.Pixel);
                                }
                            }
                            index = 8 * lvl + j;
                            using (var b = new Bitmap(w, w))
                            {
                                sx = w * (index % 8);
                                sy = w * (index / 8);
                                srcRect = new SysRect(sx, sy, w, w);
                                using (var g = Graphics.FromImage(b))
                                    g.DrawImage(template, new SysRect(0, 0, w, w), srcRect, System.Drawing.GraphicsUnit.Pixel);
                                data[index] = b.ToTexture(GraphicsDevice);
                            }
                        }
                    }
                }
            }
            return data;
        }