Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        public void Draw(Tilemap map, VectorInt _, Vector locationToDraw, Color?color)
        {
            if (prevFrameCount != DF.Window.TotalFrame)
            {
                if (timer > Interval)
                {
                    animationState++;
                    if (animationState >= Animations.Length)
                    {
                        animationState = 0;
                    }
                    timer = 0;
                }

                Texture = Animations[animationState];
                timer  += Time.DeltaTime;
            }
            prevFrameCount = DF.Window.TotalFrame;
            DF.TextureDrawer.Draw(Texture, locationToDraw, map.AbsoluteScale, color);
        }
Exemple #2
0
 public static Shape CreatePixel(VectorInt p, Color color)
 => new(color, ShapeType.Pixel, 0, null, p);
Exemple #3
0
 public Tilemap(VectorInt tileSize)
 {
     TileSize = tileSize;
     tiles    = new Dictionary <VectorInt, (ITile tile, Color?color)>();
 }
Exemple #4
0
 private static Texture2D[][] LoadAndSplitFrom(string path, int frameLength, VectorInt size)
 {
     return(LoadAndSplitFrom(File.OpenRead(path), frameLength, size));
 }
Exemple #5
0
        private static Texture2D[][] LoadAndSplitFrom(Stream stream, int frameLength, VectorInt size)
        {
            var width  = frameLength * 2;
            var height = 10;
            var tex    = new Texture2D[frameLength][];
            var temp   = Texture2D.LoadAndSplitFrom(stream, width, height, size / 2);

            for (var ix = 0; ix < width; ix += 2)
            {
                var buf = new Texture2D[height * 2];
                var i   = 0;
                for (var iy = 0; iy < height; iy++)
                {
                    var offset = iy * width + ix;
                    buf[i + 0] = temp[offset + 0];
                    buf[i + 1] = temp[offset + 1];
                    i         += 2;
                }
                tex[ix / 2] = buf;
            }
            return(tex);
        }
Exemple #6
0
 /// <summary>
 /// Initialize a new instance of  <see cref="Texture2D"/> with the specified handle and size.
 /// </summary>
 /// <param name="handle"></param>
 /// <param name="size"></param>
 public Texture2D(int handle, VectorInt size)
 {
     Handle = handle;
     Size   = size;
 }
Exemple #7
0
 /// <summary>
 /// 画像ファイルを指定して、タイルを生成します。
 /// </summary>
 /// <param name="stream">ファイルを示すストリーム。</param>
 /// <param name="frameLength">アニメーションするフレームの枚数。</param>
 /// <param name="size">画像1枚あたりのサイズ。</param>
 /// <param name="interval">画像1枚あたりのインターバル。秒単位。</param>
 /// <returns>生成されたタイル。</returns>
 public static AutoTile LoadFrom(Stream stream, int frameLength, VectorInt size, double interval = 0) => new AutoTile(LoadAndSplitFrom(stream, frameLength, size), interval);
Exemple #8
0
 /// <summary>
 /// Reads an image file and cuts it out in order from the top left at the specified size.
 /// </summary>
 /// <returns>All the image data cut out.</returns>
 /// <param name="stream">File stream</param>
 /// <param name="horizonalCount">The number of images in the horizontal direction.</param>
 /// <param name="verticalCount">The number of images in the vertical direction.</param>
 /// <param name="sizeOfCroppedImage">The size of a piece of image.</param>
 public static  Texture2D[] LoadAndSplitFrom(Stream stream, int horizonalCount, int verticalCount, VectorInt sizeOfCroppedImage)
 {
     return(LoadAndSplitFrom(Image.Load(stream), horizonalCount, verticalCount, sizeOfCroppedImage));
 }
Exemple #9
0
        private static Texture2D[] LoadAndSplitFrom(Image bmp, int horizonalCount, int verticalCount, VectorInt sizeOfCroppedImage)
        {
            using (bmp)
                using (var img = bmp.CloneAs <Rgba32>())
                {
                    var datas = new List <Texture2D>();

                    for (int y = 0; y < verticalCount; y++)
                    {
                        for (int x = 0; x < horizonalCount; x++)
                        {
                            (var px, var py) = (x * sizeOfCroppedImage.X, y *sizeOfCroppedImage.Y);
                            if (px + sizeOfCroppedImage.X > img.Width)
                            {
                                throw new ArgumentException(nameof(horizonalCount));
                            }
                            if (py + sizeOfCroppedImage.Y > img.Height)
                            {
                                throw new ArgumentException(nameof(verticalCount));
                            }
                            using var cropped = img.Clone(ctx => ctx.Crop(new Rectangle(px, py, sizeOfCroppedImage.X, sizeOfCroppedImage.Y)));
                            datas.Add(LoadFrom(cropped));
                        }
                    }
                    return(datas.ToArray());
                }
        }
Exemple #10
0
 /// <summary>
 /// Generate a solid color texture with specified color and size.
 /// </summary>
 /// <returns>Generated texture.</returns>
 public static Texture2D CreateSolid(SD.Color color, VectorInt size) => CreateSolid(color, size.X, size.Y);
Exemple #11
0
 public static VectorInt ToVirtualCoord(this VectorInt v)
 => (VectorInt)((Vector)v / Dpi);
Exemple #12
0
 public static VectorInt ToDeviceCoord(this VectorInt v)
 => (VectorInt)((Vector)v * Dpi);
Exemple #13
0
        private static   Texture2D[] LoadFrom(Image bitmap, int left, int top, int right, int bottom, out VectorInt size)
        {
            using var img = bitmap.CloneAs <Rgba32>();
            bitmap.Dispose();

            size = (img.Width, img.Height);

            if (left > img.Width)
            {
                throw new ArgumentException(nameof(left));
            }
            if (top > img.Height)
            {
                throw new ArgumentException(nameof(top));
            }
            if (right > img.Width - left)
            {
                throw new ArgumentException(nameof(right));
            }
            if (bottom > img.Height - top)
            {
                throw new ArgumentException(nameof(bottom));
            }

            var atlas = new[]
            {
                new Rectangle(0, 0, left, top),
                new Rectangle(left, 0, img.Width - left - right, top),
                new Rectangle(img.Width - right, 0, right, top),
                new Rectangle(0, top, left, img.Height - top - bottom),
                new Rectangle(left, top, img.Width - left - right, img.Height - top - bottom),
                new Rectangle(img.Width - right, top, right, img.Height - top - bottom),
                new Rectangle(0, img.Height - bottom, left, bottom),
                new Rectangle(left, img.Height - bottom, img.Width - left - right, bottom),
                new Rectangle(img.Width - right, img.Height - bottom, right, bottom),
            };

            return(atlas.Select(a =>
            {
                using var locked = img.Clone(ctx => ctx.Crop(a));
                return Texture2D.LoadFrom(locked);
            }).ToArray());
        }
Exemple #14
0
 public Graphic Pixel(VectorInt p, Color color)
 {
     Add(Shape.CreatePixel(p, color));
     return(this);
 }