【发布时间】:2025-12-26 15:20:16
【问题描述】:
如何将任意 Texture2D 中的每个非透明像素设置为暂时使用 Color.White?
【问题讨论】:
-
你的意思是你想真正改变纹理吗?或者只是把它画成白色?如果您正在绘图,您可以使用着色器check out this answer,注意它引用了外部着色器,但它并不太复杂。
标签: c# colors xna sprite textures
如何将任意 Texture2D 中的每个非透明像素设置为暂时使用 Color.White?
【问题讨论】:
标签: c# colors xna sprite textures
尚未对此进行测试,但在我看来,您可以这样做:
Color[] az = Enumerable.Range(0, 100).Select(i => Color.White).ToArray();
Texture2D texture = new Texture2D(GameRef.GraphicsDevice, 10, 10, false, SurfaceFormat.Color);
texture.SetData(az);
这首先创建一个包含 100 个元素的数组,并用 Color.White 填充它 然后使用 SetData,我们用 colorarray 填充它。
只要确保数组的大小与纹理大小相同(高*宽)
【讨论】:
只是一个条件循环?这不是它的确切语法,而是以下行中的一些内容:
Texture2D texture = /*copy the texture you want to change*/;
Pixel pixel;/*note it's really inexact, so don't mind it, the idea is to show how it would be done*/
for(int i=0; i<texture.width; i++)
{
for(int j=0; j<texture.height; j++)
{
pixel = texture.GetPixel(i, j);
if(pixel.Color.A==1)
pixel.Color = Color.White;
}
}
我怎么强调都不为过:不要只是复制粘贴,这类似于伪代码,只是为了展示它是如何完成的。
【讨论】: