当前位置: 首页>>代码示例>>C#>>正文


C# TileSet.GetTileInfo方法代码示例

本文整理汇总了C#中TileSet.GetTileInfo方法的典型用法代码示例。如果您正苦于以下问题:C# TileSet.GetTileInfo方法的具体用法?C# TileSet.GetTileInfo怎么用?C# TileSet.GetTileInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TileSet的用法示例。


在下文中一共展示了TileSet.GetTileInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TerrainBitmap

        public static Bitmap TerrainBitmap(TileSet tileset, Map map, bool actualSize = false)
        {
            var isDiamond = map.TileShape == TileShape.Diamond;
            var b = map.Bounds;

            // Fudge the heightmap offset by adding as much extra as we need / can.
            // This tries to correct for our incorrect assumption that MPos == PPos
            var heightOffset = Math.Min(map.MaximumTerrainHeight, map.MapSize.Y - b.Bottom);
            var width = b.Width;
            var height = b.Height + heightOffset;

            var bitmapWidth = width;
            if (isDiamond)
                bitmapWidth = 2 * bitmapWidth - 1;

            if (!actualSize)
                bitmapWidth = height = Exts.NextPowerOf2(Math.Max(bitmapWidth, height));

            var terrain = new Bitmap(bitmapWidth, height);

            var bitmapData = terrain.LockBits(terrain.Bounds(),
                ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            var mapTiles = map.MapTiles.Value;

            unsafe
            {
                var colors = (int*)bitmapData.Scan0;
                var stride = bitmapData.Stride / 4;
                for (var y = 0; y < height; y++)
                {
                    for (var x = 0; x < width; x++)
                    {
                        var uv = new MPos(x + b.Left, y + b.Top);
                        var type = tileset.GetTileInfo(mapTiles[uv]);
                        var leftColor = type != null ? type.LeftColor : Color.Black;

                        if (isDiamond)
                        {
                            // Odd rows are shifted right by 1px
                            var dx = uv.V & 1;
                            var rightColor = type != null ? type.RightColor : Color.Black;
                            if (x + dx > 0)
                                colors[y * stride + 2 * x + dx - 1] = leftColor.ToArgb();

                            if (2 * x + dx < stride)
                                colors[y * stride + 2 * x + dx] = rightColor.ToArgb();
                        }
                        else
                            colors[y * stride + x] = leftColor.ToArgb();
                    }
                }
            }

            terrain.UnlockBits(bitmapData);
            return terrain;
        }
开发者ID:rhamilton1415,项目名称:OpenRA,代码行数:57,代码来源:Minimap.cs

示例2: TerrainBitmap

        public static Bitmap TerrainBitmap(TileSet tileset, Map map, bool actualSize = false)
        {
            var b = map.Bounds;
            var width = b.Width;
            var height = b.Height;

            if (!actualSize)
                width = height = Exts.NextPowerOf2(Math.Max(b.Width, b.Height));

            var terrain = new Bitmap(width, height);

            var bitmapData = terrain.LockBits(terrain.Bounds(),
                ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            var mapTiles = map.MapTiles.Value;

            unsafe
            {
                var colors = (int*)bitmapData.Scan0;
                var stride = bitmapData.Stride / 4;
                for (var y = 0; y < b.Height; y++)
                {
                    for (var x = 0; x < b.Width; x++)
                    {
                        var mapX = x + b.Left;
                        var mapY = y + b.Top;
                        var type = tileset.GetTileInfo(mapTiles[new MPos(mapX, mapY)]);
                        var color = type != null ? type.LeftColor : Color.Black;

                        colors[y * stride + x] = color.ToArgb();
                    }
                }
            }

            terrain.UnlockBits(bitmapData);
            return terrain;
        }
开发者ID:zombie-einstein,项目名称:OpenRA,代码行数:37,代码来源:Minimap.cs


注:本文中的TileSet.GetTileInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。