Jamey
Jamey

Reputation: 47

How to load textures to XNA?

Alright, so I need a texture for a game that I'm making and I found a texture that fit to my project(some kind of ball). The texture is next to other textures(Textures sheet). So I had to download all the sheet. Now, I need to get only the texure that I want (that ball). And I can only circle it by a rectangle(using Paint). Is it true that XNA has an ignorant color? Or there's any other way that I can load ONLY MY BALL? and not the background of it?

Please, I really need an answer for it.. Thanks alot.

Upvotes: 0

Views: 713

Answers (1)

Andrew Russell
Andrew Russell

Reputation: 27215

To enable colour-key transparency, select your texture in your content project and press F4 to bring up the properties window. Expand the "Content Processor" option to reveal the colour key settings. Turn on colour key and select the appropriate colour.

If you need to use a sprite sheet within XNA (ie: if you're not cropping it in your image editor), you can use the sourceRectangle parameter to SpriteBatch.Draw to treat only a particular rectangular region of your source texture as a sprite.

By default SpriteBatch will draw with BlendState.AlphaBlend (ie: if you use the Begin() overload, you don't need to set it), which will correctly handle the transparency for you.

Upvotes: 2

Related Questions