Microsoft.Xna.Framework.Graphics.SpriteBatch.Begin C# (CSharp) Method

Begin() public method

Begins a new sprite and text batch with the specified render state.
This method uses optional parameters. The Begin Begin should be called before drawing commands, and you cannot call it again before subsequent End.
Thrown if is called next time without previous .
public Begin ( SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null, System.Matrix transformMatrix = null ) : void
sortMode SpriteSortMode The drawing order for sprite and text drawing. by default.
blendState BlendState State of the blending. Uses if null.
samplerState SamplerState State of the sampler. Uses if null.
depthStencilState DepthStencilState State of the depth-stencil buffer. Uses if null.
rasterizerState RasterizerState State of the rasterization. Uses if null.
effect Effect A custom to override the default sprite effect. Uses default sprite effect if null.
transformMatrix System.Matrix An optional matrix used to transform the sprite geometry. Uses if null.
return void
        public void Begin
        (
             SpriteSortMode sortMode = SpriteSortMode.Deferred,
             BlendState blendState = null,
             SamplerState samplerState = null,
             DepthStencilState depthStencilState = null,
             RasterizerState rasterizerState = null,
             Effect effect = null,
             Matrix? transformMatrix = null
        )
        {
            if (_beginCalled)
                throw new InvalidOperationException("Begin cannot be called again until End has been successfully called.");

            // defaults
            _sortMode = sortMode;
            _blendState = blendState ?? BlendState.AlphaBlend;
            _samplerState = samplerState ?? SamplerState.LinearClamp;
            _depthStencilState = depthStencilState ?? DepthStencilState.None;
            _rasterizerState = rasterizerState ?? RasterizerState.CullCounterClockwise;
            _effect = effect;
            _matrix = transformMatrix ?? Matrix.Identity;

            // Setup things now so a user can change them.
            if (sortMode == SpriteSortMode.Immediate)
            {
                Setup();
            }

            _beginCalled = true;
        }

Usage Example

Example #1
5
 public override void ReflectionRender(SpriteBatch spriteBatch)
 {
     if (this.txTexture == RenderMaster.txNullTex)
     {
         return;
     }
     this.txToUse = this.txTexture;
     if (this.dentxAlternateTextures.ContainsKey(RenderMaster.enCurrentPass))
     {
         this.txToUse = this.dentxAlternateTextures[RenderMaster.enCurrentPass];
     }
     if (base.xEffectWrapper == null)
     {
         spriteBatch.Draw(this.txToUse, Utility.Vector2_ToInts(this.xTransform.v2Pos - this.v2OffsetRenderPos) - Utility.Vector2_ToInts(this.xCamera.v2TopLeft * this.v2ParallaxFactor), null, this.cColor * this.fAlpha, this.fRotation, new Vector2(this.v2Offset.X, (float)this.txTexture.Height - this.v2Offset.Y), this.v2Scale, this.enSpriteEffect | SpriteEffects.FlipVertically, 0f);
         return;
     }
     spriteBatch.End();
     foreach (KeyValuePair<string, float> kvp in this.dsfFloatShaderParameters)
     {
         base.xEffectWrapper.xEffect.Parameters[kvp.Key].SetValue(kvp.Value);
     }
     spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, null, base.xEffectWrapper.xEffect);
     spriteBatch.Draw(this.txToUse, Utility.Vector2_ToInts(this.xTransform.v2Pos - this.v2OffsetRenderPos) - Utility.Vector2_ToInts(this.xCamera.v2TopLeft * this.v2ParallaxFactor), null, this.cColor * this.fAlpha, this.fRotation, new Vector2(this.v2Offset.X, (float)this.txTexture.Height - this.v2Offset.Y), this.v2Scale, this.enSpriteEffect | SpriteEffects.FlipVertically, 0f);
     spriteBatch.End();
     spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, null);
 }
All Usage Examples Of Microsoft.Xna.Framework.Graphics.SpriteBatch::Begin