共用方式為


RenderState.AlphaBlendEnable Property

Gets or sets a value to enable alpha-blended transparency. The default value is false.

Namespace: Microsoft.Xna.Framework.Graphics
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

Syntax

public bool AlphaBlendEnable { get; set; }

Property Value

true if alpha-blended transparency is enabled; false otherwise.

Remarks

The alpha value of a color controls its transparency. Enabling alpha blending with AlphaBlendEnable allows colors, materials, and textures on a surface to be blended with transparency onto another surface.

Alpha blending is determined by the SourceBlend and DestinationBlend properties. With the default BlendFunction, the source pixel times the SourceBlend is added to the destination pixel (the pixel on the back buffer) times the DestinationBlend to produce a color that is a blend of the two pixel colors. The BlendFunction determines the operation used on the outcome of the source blend and destination blend components.

Example

The following short code snippet sets the render state to use additive alpha blending prior to a draw call.

graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true;
graphics.GraphicsDevice.RenderState.SourceBlend = Blend.One;
graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.One;
graphics.GraphicsDevice.RenderState.BlendFunction = BlendFunction.Add;

// TODO: Place the drawing calls that should be alpha blended here.

See Also

Reference

SourceBlend
DestinationBlend
BlendFunction
RenderState Class
RenderState Members
Microsoft.Xna.Framework.Graphics Namespace

Platforms

Xbox 360, Windows XP SP2, Windows Vista