Jump to content
  • Advertisement
Sign in to follow this  
OneWigedAngel84

C# Transparent Sprite

This topic is 4036 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

Hi guys! i need your experience: I'm trying to set an alpha value for my sprite that, when it point to zero, it should be invisible. I'm not talking about color key that makes me set only one color transparent, but i want the entire sprite does. Is that possibile in DirectX 9.0? I hope so! ;) Thanks everibody, have a nice day.

Share this post


Link to post
Share on other sites
Advertisement
Sprite.Draw() has an int color parameter which sets the filter and alpha your sprite will be rendered with.

If you set this parameter with Color.White.ToArgb() you'll get your sprite rendered opaque and in it's original color. If you use something like Color.FromArgb(128,Color.White) your sprite will be rendered semitransparent and in it's original color. So if you change 128 to 0 your sprite will be transparent. You can play with those values to create a sprite that disappears smoothly instead of disappearing instantly, but if you only want to make it transparent you should declare a Visible property for your custom sprite class so your rendering method checks it's value and renders the sprite only if it's visible. This way your sprite won't be rendered and you'll avoid to render with an alpha 0. I have both options in my framework so I can use both techniques according to my needs.

Regards

Share this post


Link to post
Share on other sites
Trying to write down some code i've notice that i really need to set Alpha parameter with a float value. Is that possible or the only way to set it is with int value beetwen 0-255?

Please, i need help.
Have a great day!

Share this post


Link to post
Share on other sites
Quote:
Original post by OneWigedAngel84
Trying to write down some code i've notice that i really need to set Alpha parameter with a float value. Is that possible or the only way to set it is with int value beetwen 0-255?

Please, i need help.
Have a great day!

Whether or not you use more precision, the graphics hardware is still only going to work with 8 bits (256 levels). Why can't you just convert your float to the appropriate int? The difference between, say, alpha 245 and alpha 246 is very difficult to notice...

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!