Sign in to follow this  
OneWigedAngel84

C# Transparent Sprite

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
Hyper Sonic    136
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
MasterWorks    496
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this