# XNA How to change the sprite texture to white color

as the title,

how can i do to take the sprite to white color

here is some example,

turn to follows image

and my game planform is XNA now, and developed winphone game

• Could you explain a bit more. Maybe give better pictures? Do you want to change the entire texture to white? Or just colour in a part? – Roy T. Aug 22 '14 at 13:24
• entire texture to white – 黃泓鳴 Aug 23 '14 at 13:20

You can use Texture2D.GetData() to copy texture pixel data to a Color[] in XNA.

Texture2D texture=Content.Load<Texture2D>("asd");
Color[] tcolor=new Color[texture.Width*texture.Height];
texture.GetData<Color>(tcolor);


After you have your Color array, you can do whatever you want with it, for example you could change certain colored pixels to Color.White. Then you set this data to the texture. You can use Texture2D.SetData() for this:

texture.SetData<Color>(tcolor);

• Instead of just flat out changing certain pixels to white... is there some sort of calculation that could be done to apply more of a overall effect to the sprite? I think what the OP is looking for is something along the lines of the behavior of changing the diffuse color but since to get the natural color of the sprite you use white, the question becomes how to do whiten a sprite. – SpartanDonut Aug 22 '14 at 15:14
• Well, this is what came to my mind, the question is not clear enough. Certain 2D games let the user change the color palette of a sprite, I thought about something like that. – János Turánszki Aug 22 '14 at 15:43

Try this

spriteBatch.Draw(sprite, position, Color.Red);

• This would only tint the sprite as a whole - what about making this into a function as well? – Tom 'Blue' Piddock Sep 15 '14 at 13:45

this works for me, at the beginning of the code, the color is loaded, and a new color is created, after that we change the color to the desired color in the for loop:

protected override void Initialize()
{
Color[] data = new Color[sprite.Width * sprite.Height];
sprite.GetData(data);
// cor nova
Color novaCor =Color.Blue;

for (int i = 0; i < data.Length; i++)
{
if (data[i].R == 142
&& data[i].G == 24
&& data[i].B == 115)
{
data[i] = novaCor;
}
}
sprite.SetData<Color>(data);

posicaoNinja = new Vector2(0, 200);

base.Initialize();
}

• it's a right answer but you are worried about my format, please edit the document but don´t mark as wrong answer.. – Igor Monteiro Nov 9 '17 at 20:19