XNA Creators Club Online
Page 1 of 1 (16 items)
Sort Posts: Previous Next

Alpha Blending Sprites

Last post 5/11/2009 4:54 PM by Zero Serenity. 15 replies.
  • 5/10/2009 3:29 AM

    Alpha Blending Sprites

    My game is comming along nicely. Working as indended (minus all the art obviously) and is generaly effective. At the moment though, I have not seen a real great way to turn a sprite semi-transparent against a background or another sprite. I am largely confused by some of the library information; Is there a good practice way to do this?
  • 5/10/2009 5:18 AM In reply to

    Re: Alpha Blending Sprites

    When you use SpriteBatch.Draw, you specify a color. That color has an alpha channel
    Regards,
    Louis Ingenthron
    Fortis Venaliter
    Lead Developer of FV ProductionsFV Productions
  • 5/10/2009 5:28 AM In reply to

    Re: Alpha Blending Sprites

    Okay, let me be a bit more specific. I specifiy the proper alpha channel and all, but my objective is to make the sprite entirely translucent, not just the specified alpha channel.
  • 5/10/2009 6:30 AM In reply to

    Re: Alpha Blending Sprites

    You mean you want transparent areas around opaque areas, instead of just fading out the whole entire graphic?

    If so, then simply utilize the alpha channel in your image editor of choice, and save in a format like PNG when importing it into Visual Studio.
  • 5/10/2009 6:45 AM In reply to

    Re: Alpha Blending Sprites

    When you call SpriteBatch.Begin it has the first parameter SpriteBlendMode.

    The resulting pixel under each of the blending modes.
    Existing Pixel = the one currently on the image
    Current Pixel = the one your drawing
    SpriteBlendMode.None = Current Pixel rgb
    SpriteBlendMode.Additive = Existing Pixel rgb + (Current Pixel rgb * Current pixel alpha)
    SpriteBlendMode.Subtractive = Existing Pixel rgb - (Current Pixel rgb * Current pixel alpha)
    SpriteBlendMode.AlphaBlend = Existing Pixel rgb + ((Current Pixel rgb - Existing Pixel rgb) * Current Pixel alpha)
  • 5/10/2009 7:21 AM In reply to

    Re: Alpha Blending Sprites

    This is sorta like what I want, buut this isn't excactly descriptive on how to use it. Can you go into depth?
  • 5/10/2009 10:29 AM In reply to

    Re: Alpha Blending Sprites

    Zero Serenity:
    Okay, let me be a bit more specific. I specifiy the proper alpha channel and all, but my objective is to make the sprite entirely translucent, not just the specified alpha channel.
    I don't get it. the "specified alpha channel" does fade out the whole sprite. 0.5f and you will be able to see half the BG behind it. Or are you talking about the bordering pixels? Please try to be as specific as you can. Instead of "the alpha channel", say something like "the alpha channel in the color passed in spritebatch.draw", etc. Also, screenshots help.
    Regards,
    Louis Ingenthron
    Fortis Venaliter
    Lead Developer of FV ProductionsFV Productions
  • 5/10/2009 3:24 PM In reply to

    Re: Alpha Blending Sprites

    FortisVenaliter Productions:
    Zero Serenity:
    Okay, let me be a bit more specific. I specifiy the proper alpha channel and all, but my objective is to make the sprite entirely translucent, not just the specified alpha channel.
    0.5f and you will be able to see half the BG behind it.
    This sentence is excactly what I want! But I'm unsure how to pull it off.
  • 5/10/2009 3:29 PM In reply to

    Re: Alpha Blending Sprites

    Color color = Color.White;
    color.A = 128;
    SpriteBatch.Draw(tex, pos, color);

    this will draw your entire sprite at half (256/2) transparency

    Game hobbyist hell-bent on coding a diabolical Matrix
  • 5/10/2009 8:42 PM In reply to

    Re: Alpha Blending Sprites

    Craig Martin:
    Color color = Color.White;
    color.A = 128;
    SpriteBatch.Draw(tex, pos, color);

    this will draw your entire sprite at half (256/2) transparency

    As I said in the second post
    Regards,
    Louis Ingenthron
    Fortis Venaliter
    Lead Developer of FV ProductionsFV Productions
  • 5/10/2009 11:54 PM In reply to

    Re: Alpha Blending Sprites

    FortisVenaliter Productions:
    Craig Martin:
    Color color = Color.White;
    color.A = 128;
    SpriteBatch.Draw(tex, pos, color);

    this will draw your entire sprite at half (256/2) transparency

    As I said in the second post


    If your talking to me, I'm aware you said that, but the OP seemed to not follow.
    Game hobbyist hell-bent on coding a diabolical Matrix
  • 5/11/2009 7:11 AM In reply to

    Re: Alpha Blending Sprites

    Craig Martin:
    Color color = Color.White;
    color.A = 128;
    SpriteBatch.Draw(tex, pos, color);

    this will draw your entire sprite at half (256/2) transparency



    Or to be a little less verbose:

    spriteBatch.Draw(texture, position, new Color(Color.White, 128));


    Color's constructor also accepts a base color and an alpha value.
  • 5/11/2009 7:23 AM In reply to

    Re: Alpha Blending Sprites

    Done with this section already as of yesterday. Thanks. Might have more problems as they come, but oh well. Before I make a new thread, let me derail this one quite a bit and ask, is there a way to add pre-rendered cinematics or some sort of library that would allow for watching AVI/MPG videos? (No, this will not infringe copyrights, there is a point to this)
  • 5/11/2009 8:01 AM In reply to

    Re: Alpha Blending Sprites

    Its been announced for XNA 3.1, which (as far as we know) should be out in a few months
    Regards,
    Louis Ingenthron
    Fortis Venaliter
    Lead Developer of FV ProductionsFV Productions
  • 5/11/2009 12:10 PM In reply to

    Re: Alpha Blending Sprites

    In your sprite batch begin:
    SpriteBatch.Begin(SpriteBlendMode.None);

    That part between the ( ) is the parameters of the begin call, I thought I was being entirely too descriptive.

    Edit : NVM about the above, your wording had me screwed up on what you meant.

    I really think you need to learn a bit more about the language/api if something this simple is plaguing you for more than a couple days.
  • 5/11/2009 4:54 PM In reply to

    Re: Alpha Blending Sprites

    And...why do you think I'm here?
Page 1 of 1 (16 items) Previous Next