public void SetOpacity(float opacity) { if (Opacity == opacity) { return; } Sprite.Flush(); var newBlendState = Device.BlendState.Clone(); if (opacity >= 1 || opacity < 0) { newBlendState.ColorSourceBlend = Blend.SourceAlpha; newBlendState.ColorDestinationBlend = Blend.InverseSourceAlpha; newBlendState.AlphaSourceBlend = Blend.One; newBlendState.BlendFactor = new Color(255, 255, 255, 255); Device.BlendState = newBlendState; DisableAlphaTest(); } else { EnableAlphaTest(); newBlendState.ColorSourceBlend = Blend.BlendFactor; newBlendState.ColorDestinationBlend = Blend.InverseBlendFactor; newBlendState.AlphaSourceBlend = Blend.SourceAlpha; newBlendState.BlendFactor = new Color((byte)(255 * opacity), (byte)(255 * opacity), (byte)(255 * opacity), (byte)(255 * opacity)); Device.BlendState = newBlendState; } Opacity = opacity; Sprite.Flush(); }
public void SetBlend(bool value, float rate = 1F) { if (value == Blending) { return; } Blending = value; BlendRate = 1F; Sprite.Flush(); Sprite.End(); if (Blending) { Sprite.Begin(SpriteFlags.DoNotSaveState); EnableAlphaTest(); var newBlendState = Device.BlendState.Clone(); newBlendState.ColorSourceBlend = Blend.BlendFactor; newBlendState.ColorDestinationBlend = Blend.One; newBlendState.BlendFactor = new Color((byte)(255 * rate), (byte)(255 * rate), (byte)(255 * rate), (byte)(255 * rate)); Device.BlendState = newBlendState; } else { Sprite.Begin(SpriteFlags.AlphaBlend); } Device.SetRenderTarget(CurrentRenderTarget); }
public void SetRenderTarget(RenderTarget2D renderTarget) { if (CurrentRenderTarget == renderTarget) { return; } Sprite.Flush(); CurrentRenderTarget = renderTarget; Device.SetRenderTarget(renderTarget); }