How to use Texture Alpha Blending like SpriteBatch?

Apr 23, 2009 at 2:50 PM
hi.
I would like to know how to Alphablending of TexturedElement in Xen. It was possible to use SpriteBatch easily. 

    spriteBatch.Draw (texture, size, new Color (fade, fade, fade));

How to make a simple 2D texture to be transparent in Xen?
Coordinator
Apr 23, 2009 at 10:55 PM
Hello. All classes extending from Element have a 'AlphaBlendState' property, this property can be set to any alpha blending mode you may want.
For example, if you want simple interpolated blending (traditional alpha blending) then the AlphaBlendState class has a static called 'Alpha' which you can use.
element.AlphaBlendState = AlphaBlendState.Alpha;

Or, you could use one of the other statics, or a custom alpha blend state.
Hope that helps.

Coordinator
Apr 24, 2009 at 2:36 AM
Edited Apr 24, 2009 at 3:26 AM

Sorry I misread the question.

There are two ways you could set the colour of a sprite.
One, if you want an alternative to SpriteBatch, you can use the SpriteElement - which allows you to set the colour of each sprite. SpriteElement is designed to draw loads of sprites in one go, it's not really designed to draw single sprites.

Or... And this is the more complex option..
TexturedElement doesn't directly expose a method to set it's vertex colours. However, you could create a class that extends from TexturedElement and overrides the 'WriteColours' method - which simply sets all the vertex colours to white for the default TexturedElement implementation.

Apr 24, 2009 at 2:55 AM
Oh, Thanks for your help.


I have already tried to use the first solution, but  instead of  Aplha Bleding,  it changed color (ex, Color = (0, 0, 0), Not Alphablending, But Texture is presented Black.)

so, I will try to use the latter solution.

thank you.

Coordinator
Apr 24, 2009 at 3:29 AM
That sounds like correct behaviour. The colour you specify is Red,Green,Blue,Alpha, the RGB is multiplied by the texture colour, so 0,0,0 * texture colour will always be black. If you want to fade out the texture, then you need to modify the alpha value.
Either that, or you want to be using a different blending mode, such as Additive, where Current Colour + black makes no change (and is effectively transparent).

Hope that makes sense.

Apr 24, 2009 at 10:59 AM
Thank you very much for your help.
It has succeeded in AlphaBlending.
Xen is really good.