本文整理汇总了C#中Texture2D.WriteRegion方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.WriteRegion方法的具体用法?C# Texture2D.WriteRegion怎么用?C# Texture2D.WriteRegion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texture2D
的用法示例。
在下文中一共展示了Texture2D.WriteRegion方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AtlasTileSet
public AtlasTileSet(TileInfo[] tiles)
{
var tileResolution = tiles[0].Source.Width;
ValidateResolution(tileResolution, tiles);
var atlasSize = CalculateAtlasSize(tiles.Length);
var textureSize = atlasSize * tileResolution;
var atlasBitmap = new Bitmap(textureSize, textureSize);
var x = 0;
var y = 0;
using (var graphics = Graphics.FromImage(atlasBitmap))
{
graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
for (var n = 0; n < tiles.Length; n++)
{
tiles[n].Source.Render(graphics, x, y);
x += tileResolution;
if (x >= textureSize)
{
x = 0;
y += tileResolution;
if (y >= textureSize)
{
throw new Exception("The texture atlas is too small.");
}
}
}
}
var atlasTexture = new Texture2D(atlasBitmap.Width, atlasBitmap.Height)
{
MinificationFilter = TextureMinFilter.Nearest,
MagnificationFilter = TextureMagFilter.Nearest
};
atlasTexture.WriteRegion(atlasBitmap);
Initialize(atlasTexture, atlasSize, atlasSize);
for (var n = 0; n < tiles.Length; n++)
{
SetTileName(n, tiles[n].Name);
}
}