C#XNA如何将纹理2D设置为单色?

C#XNA如何将纹理2D设置为单色?,c#,colors,xna,sprite,textures,C#,Colors,Xna,Sprite,Textures,如何将任意纹理2D中的每个不透明像素设置为颜色。暂时设置为白色 只是一个条件循环?这不是它的确切语法,而是以下几行: 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.wid

如何将任意纹理2D中的每个不透明像素设置为颜色。暂时设置为白色

只是一个条件循环?这不是它的确切语法,而是以下几行:

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;
  }
}
Texture2D texture=/*复制要更改的纹理*/;
像素/*请注意,这确实是不精确的,所以不要介意,这个想法是为了展示如何做到这一点*/

对于(int i=0;i来说,我还没有测试过这一点,但是在我的头脑中,你可以这样做:

  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填充它


只需确保数组的大小与纹理大小(高度*宽度)相同即可。

您的意思是要实际更改纹理?还是只将其绘制为白色?如果要绘制纹理,可以使用着色器,请注意它引用外部着色器,但并不太复杂。OP不想设置每个像素,只设置不透明的像素