2
\$\begingroup\$

as the title,

how can i do to take the sprite to white color

here is some example,

enter image description here

turn to follows image

enter image description here

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

thanks for reading!

\$\endgroup\$
  • 2
    \$\begingroup\$ 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? \$\endgroup\$ – Roy T. Aug 22 '14 at 13:24
  • \$\begingroup\$ entire texture to white \$\endgroup\$ – 黃泓鳴 Aug 23 '14 at 13:20
3
\$\begingroup\$

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);
| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – SpartanDonut Aug 22 '14 at 15:14
  • \$\begingroup\$ 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. \$\endgroup\$ – János Turánszki Aug 22 '14 at 15:43
1
\$\begingroup\$

Try this

spriteBatch.Draw(sprite, position, Color.Red);
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ This would only tint the sprite as a whole - what about making this into a function as well? \$\endgroup\$ – Tom 'Blue' Piddock Sep 15 '14 at 13:45
-2
\$\begingroup\$

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()
        {
            sprite = Content.Load<Texture2D>("Parado");
            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++)
            {
                // include your RGB color
                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();
        }
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ it's a right answer but you are worried about my format, please edit the document but don´t mark as wrong answer.. \$\endgroup\$ – Igor Monteiro Nov 9 '17 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.