1
我該如何使用代碼來程序化地生成一個Texture2D? (例如:我希望交替像素在32x32圖像上是黑白的)在Xna/MonoGame中程序化地生成一個Texture2D
我該如何使用代碼來程序化地生成一個Texture2D? (例如:我希望交替像素在32x32圖像上是黑白的)在Xna/MonoGame中程序化地生成一個Texture2D
您可以使用GraphicsDevice創建一個新的texutre。
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);
所以對於一個32×32的紋理,它會在1024彩色多頭排列何時舉行? – madfjlkfafads
是的。寬x高 – GMich