如何使用代码按程序生成Texture2D? (例如:我希望在 32x32 图像上交替出现黑白像素)
您可以使用 GraphicsDevice 创建一个新的纹理。
public static Texture2D CreateTexture(GraphicsDevice device, int width,int height, Func<int,Color> paint)
{
//initialize a texture
Texture2D texture = new Texture2D(device, width, height);
//the array holds the color for each pixel in the texture
Color[] data = new Color[width * height];
for(int pixel=0;pixel<data.Count();pixel++)
{
//the function applies the color according to the specified pixel
data[pixel] = paint(pixel);
}
//set the color
texture.SetData(data);
return texture;
}
32x32 黑色纹理示例
CreateTexture(device,32,32,pixel => Color.Black);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)