Jump to content
  • Advertisement
Sign in to follow this  
boehmz

Color Keying in XNA

This topic is 3231 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a way to color key(AKA one color in your sprite doesn't show up) in XNA? I don't like my sprites showing up as rectangles, lol.

Share this post


Link to post
Share on other sites
Advertisement
2 options I can think of of the top of my head:

1) Copy the texture to another texture and while your doing it, set the chroma pixels alpha to zero.

2) do it in a shader, make sure to check the color before any lighting is applied.

There's also the option of saving your images in a format that supports alpha.

Share this post


Link to post
Share on other sites
Assuming you're adding your sprites into the Content project in your game (which you should be ;) ), you can set the color key in the sprite file's Properties under the Content Processor.

Share this post


Link to post
Share on other sites
Quote:
Original post by Machaira
Assuming you're adding your sprites into the Content project in your game (which you should be ;) ), you can set the color key in the sprite file's Properties under the Content Processor.


yep, and if you have to use Texture2D.FromFile() you can use a code like this:


TextureCreationParameters tcp = TextureCreationParameters.Default;
tcp.ColorKey = new Color(new Vector3(255, 0, 255)); // set here the color you want as your colorkey
tcp.Format = SurfaceFormat.Rgba1010102; //I tried different surfaceformat and this works well

Texture2D.FromFile(YOUR_GRAPHICSDEVICE, YOUR_PATH, tcp);


[Edited by - FOOLVER on September 14, 2009 5:13:10 PM]

Share this post


Link to post
Share on other sites
Ah good to know, thanks, never coded for 360 :(.

I just used fromfile in my map editor.

[Edited by - FOOLVER on September 15, 2009 4:54:40 AM]

Share this post


Link to post
Share on other sites
Didn't see that before, good to know it's there. Now when I use it, it seems only part of the color is keyed. The image still shows the color that is supposed to be keyed in jagged parts around it and sometimes in black. One problem might be the A value, I don't fully understand what it is. I'm also stretching the image(using a rectangle) so I'll try displaying at regular size to see if that changes anything.

Share this post


Link to post
Share on other sites
The texture filter is blending edge pixels with the keyed color. Disabling it (i.e., using a point filter) will eliminate this at the cost of making your sprites blocky when stretched. You may be better off using an alpha test instead of a color key and storing 1-bit alpha.

Share this post


Link to post
Share on other sites
Quote:
Original post by boehmz
Didn't see that before, good to know it's there. Now when I use it, it seems only part of the color is keyed. The image still shows the color that is supposed to be keyed in jagged parts around it and sometimes in black. One problem might be the A value, I don't fully understand what it is. I'm also stretching the image(using a rectangle) so I'll try displaying at regular size to see if that changes anything.



check your image with a program because it seems yor image have not clear border!

ps. avoid the use of jpg images, jpg makes artifacts!


http://www.polisportivasantachiara.it/fool/pablo/avoid.png

good on the left side, not good on the right side

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!