Stride

OPEN / CLOSE
  • Features
  • Blog
  • Documentation
  • Community
(icon) Download

  • Discord
  • Facebook
  • Twitter
  • YouTube

LANGUAGE

OPEN / CLOSE
  • English
  • 日本語
    Show / Hide Table of Contents

    SpriteBatch Class

    Namespace: Stride.Graphics
    Assembly: Stride.Graphics.dll

    Renders a group of sprites.

    System.Object → DisposeBase → ComponentBase → BatchBase<SpriteBatch.SpriteDrawInfo> → SpriteBatch
    Derived from SpriteBatch:

    public class SpriteBatch : BatchBase<SpriteBatch.SpriteDrawInfo>, IDisposable, IComponent, IReferencable, ICollectorHolder
    Name Description
    Constructors
    SpriteBatch(GraphicsDevice, Int32, Int32)

    Initializes a new instance of the SpriteBatch class.

    Properties
    DefaultDepth

    Gets or sets the default depth value used by the SpriteBatch when the VirtualResolution is not set.

    TextureSpriteFontEffect
    VirtualResolution

    Gets or sets the virtual resolution used for this SpriteBatch

    Methods
    Begin(GraphicsContext, Matrix, Matrix, SpriteSortMode, Nullable<BlendStateDescription>, SamplerState, Nullable<DepthStencilStateDescription>, Nullable<RasterizerStateDescription>, EffectInstance, Int32)

    Begins a sprite batch rendering using the specified sorting mode and blend state, sampler, depth stencil, rasterizer state objects, plus a custom effect and a 2D transformation matrix. Passing null for any of the state objects selects the default default state objects (BlendState.AlphaBlend, DepthStencilState.Default, RasterizerState.CullCounterClockwise, SamplerState.LinearClamp). Passing a null effect selects the default SpriteBatch Class shader.

    Begin(GraphicsContext, Matrix, SpriteSortMode, Nullable<BlendStateDescription>, SamplerState, Nullable<DepthStencilStateDescription>, Nullable<RasterizerStateDescription>, EffectInstance, Int32)

    Begins a sprite batch rendering using the specified sorting mode and blend state, sampler, depth stencil, rasterizer state objects, plus a custom effect and a 2D transformation matrix. Passing null for any of the state objects selects the default default state objects (BlendState.AlphaBlend, DepthStencilState.Default, RasterizerState.CullCounterClockwise, SamplerState.LinearClamp). Passing a null effect selects the default SpriteBatch Class shader.

    Begin(GraphicsContext, SpriteSortMode, EffectInstance)

    Begins a sprite batch operation using deferred sort and default state objects (BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise).

    Begin(GraphicsContext, SpriteSortMode, Nullable<BlendStateDescription>, SamplerState, Nullable<DepthStencilStateDescription>, Nullable<RasterizerStateDescription>, EffectInstance, Int32)

    Begins a sprite batch rendering using the specified sorting mode and blend state, sampler, depth stencil and rasterizer state objects, plus a custom effect. Passing null for any of the state objects selects the default default state objects (BlendState.AlphaBlend, DepthStencilState.Default, RasterizerState.CullCounterClockwise, SamplerState.LinearClamp). Passing a null effect selects the default SpriteBatch Class shader.

    CalculateDefaultProjection(Vector3)

    Calculate the default projection matrix for the provided virtual resolution.

    CalculateDefaultProjection(ref Vector3, out Matrix)

    Calculate the default projection matrix for the provided virtual resolution.

    Draw(Texture, RectangleF, Color4, Color4)

    Adds a sprite to a batch of sprites for rendering using the specified texture, destination rectangle, and color.

    Draw(Texture, RectangleF, Nullable<RectangleF>, Color4, Single, Vector2, SpriteEffects, ImageOrientation, Single, Color4, SwizzleMode)

    Adds a sprite to a batch of sprites for rendering using the specified texture, destination rectangle, source rectangle, color, rotation, origin, effects and layer.

    Draw(Texture, Vector2)

    Adds a sprite to a batch of sprites for rendering using the specified texture, position and color.

    Draw(Texture, Vector2, Color, Color4)

    Adds a sprite to a batch of sprites for rendering using the specified texture, position and color.

    Draw(Texture, Vector2, Color4, Single, Vector2, Vector2, SpriteEffects, ImageOrientation, Single)

    Adds a sprite to a batch of sprites for rendering using the specified texture, position, source rectangle, color, rotation, origin, scale, effects, and layer.

    Draw(Texture, Vector2, Color4, Single, Vector2, Single, SpriteEffects, ImageOrientation, Single)

    Adds a sprite to a batch of sprites for rendering using the specified texture, position, source rectangle, color, rotation, origin, scale, effects, and layer.

    Draw(Texture, Vector2, Nullable<RectangleF>, Color4, Color4)

    Adds a sprite to a batch of sprites for rendering using the specified texture, position, source rectangle, and color.

    Draw(Texture, Vector2, Nullable<RectangleF>, Color4, Single, Vector2, Vector2, SpriteEffects, ImageOrientation, Single, Color4)

    Adds a sprite to a batch of sprites for rendering using the specified texture, position, source rectangle, color, rotation, origin, scale, effects, and layer.

    Draw(Texture, Vector2, Nullable<RectangleF>, Color4, Single, Vector2, Single, SpriteEffects, ImageOrientation, Single, Color4, SwizzleMode)

    Adds a sprite to a batch of sprites for rendering using the specified texture, position, source rectangle, color, rotation, origin, scale, effects, and layer.

    DrawString(SpriteFont, String, Vector2, Color4, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, and color.

    DrawString(SpriteFont, String, Vector2, Color4, Single, Vector2, Vector2, SpriteEffects, Single, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, color, rotation, origin, scale, effects and layer.

    DrawString(SpriteFont, String, Single, Vector2, Color4, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, and color.

    DrawString(SpriteFont, String, Single, Vector2, Color4, Single, Vector2, Vector2, SpriteEffects, Single, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, color, rotation, origin, scale, effects and layer.

    DrawString(SpriteFont, StringBuilder, Vector2, Color4, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, and color.

    DrawString(SpriteFont, StringBuilder, Vector2, Color4, Single, Vector2, Vector2, SpriteEffects, Single, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, color, rotation, origin, scale, effects and layer.

    DrawString(SpriteFont, StringBuilder, Single, Vector2, Color4, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, and color.

    DrawString(SpriteFont, StringBuilder, Single, Vector2, Color4, Single, Vector2, Vector2, SpriteEffects, Single, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, color, rotation, origin, scale, effects and layer.

    MeasureString(SpriteFont, String, Nullable<Vector2>)

    Measure the size of the given text in virtual pixels depending on the target size.

    MeasureString(SpriteFont, String, Single, Nullable<Vector2>)

    Measure the size of the given text in virtual pixels depending on the target size.

    PrepareForRendering()
    UpdateBufferValuesFromElementInfo(ref BatchBase<SpriteBatch.SpriteDrawInfo>.ElementInfo, IntPtr, IntPtr, Int32)
    | Improve this Doc View Source

    Constructors


    SpriteBatch(GraphicsDevice, Int32, Int32)

    Initializes a new instance of the SpriteBatch class.

    public SpriteBatch(GraphicsDevice graphicsDevice, int bufferElementCount = 1024, int batchCapacity = 64)
    Parameters
    Type Name Description
    GraphicsDevice graphicsDevice

    The graphics device.

    System.Int32 bufferElementCount

    The maximum number element that can be batched in one time.

    System.Int32 batchCapacity

    The batch capacity default to 64.

    | Improve this Doc View Source

    Properties


    DefaultDepth

    Gets or sets the default depth value used by the SpriteBatch when the VirtualResolution is not set.

    public float DefaultDepth { get; set; }
    Property Value
    Type Description
    System.Single
    Remarks

    More precisely, this value represents the length "farPlane-nearPlane" used by the default projection matrix.


    TextureSpriteFontEffect

    public EffectInstance TextureSpriteFontEffect { get; }
    Property Value
    Type Description
    EffectInstance

    VirtualResolution

    Gets or sets the virtual resolution used for this SpriteBatch

    public Vector3? VirtualResolution { get; set; }
    Property Value
    Type Description
    System.Nullable<Vector3>
    | Improve this Doc View Source

    Methods


    Begin(GraphicsContext, Matrix, Matrix, SpriteSortMode, Nullable<BlendStateDescription>, SamplerState, Nullable<DepthStencilStateDescription>, Nullable<RasterizerStateDescription>, EffectInstance, Int32)

    Begins a sprite batch rendering using the specified sorting mode and blend state, sampler, depth stencil, rasterizer state objects, plus a custom effect and a 2D transformation matrix. Passing null for any of the state objects selects the default default state objects (BlendState.AlphaBlend, DepthStencilState.Default, RasterizerState.CullCounterClockwise, SamplerState.LinearClamp). Passing a null effect selects the default SpriteBatch Class shader.

    public void Begin(GraphicsContext graphicsContext, Matrix viewMatrix, Matrix projectionMatrix, SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendStateDescription? blendState = null, SamplerState samplerState = null, DepthStencilStateDescription? depthStencilState = null, RasterizerStateDescription? rasterizerState = null, EffectInstance effect = null, int stencilValue = 0)
    Parameters
    Type Name Description
    GraphicsContext graphicsContext

    The graphics context to use.

    Matrix viewMatrix

    The view matrix to use for the batch session

    Matrix projectionMatrix

    The projection matrix to use for the batch session

    SpriteSortMode sortMode

    The sprite drawing order to use for the batch session

    System.Nullable<BlendStateDescription> blendState

    The blending state to use for the batch session

    SamplerState samplerState

    The sampling state to use for the batch session

    System.Nullable<DepthStencilStateDescription> depthStencilState

    The depth stencil state to use for the batch session

    System.Nullable<RasterizerStateDescription> rasterizerState

    The rasterizer state to use for the batch session

    EffectInstance effect

    The effect to use for the batch session

    System.Int32 stencilValue

    The value of the stencil buffer to take as reference for the batch session


    Begin(GraphicsContext, Matrix, SpriteSortMode, Nullable<BlendStateDescription>, SamplerState, Nullable<DepthStencilStateDescription>, Nullable<RasterizerStateDescription>, EffectInstance, Int32)

    Begins a sprite batch rendering using the specified sorting mode and blend state, sampler, depth stencil, rasterizer state objects, plus a custom effect and a 2D transformation matrix. Passing null for any of the state objects selects the default default state objects (BlendState.AlphaBlend, DepthStencilState.Default, RasterizerState.CullCounterClockwise, SamplerState.LinearClamp). Passing a null effect selects the default SpriteBatch Class shader.

    public void Begin(GraphicsContext graphicsContext, Matrix viewMatrix, SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendStateDescription? blendState = null, SamplerState samplerState = null, DepthStencilStateDescription? depthStencilState = null, RasterizerStateDescription? rasterizerState = null, EffectInstance effect = null, int stencilValue = 0)
    Parameters
    Type Name Description
    GraphicsContext graphicsContext

    The graphics context to use.

    Matrix viewMatrix

    The view matrix to use for the batch session

    SpriteSortMode sortMode

    The sprite drawing order to use for the batch session

    System.Nullable<BlendStateDescription> blendState

    The blending state to use for the batch session

    SamplerState samplerState

    The sampling state to use for the batch session

    System.Nullable<DepthStencilStateDescription> depthStencilState

    The depth stencil state to use for the batch session

    System.Nullable<RasterizerStateDescription> rasterizerState

    The rasterizer state to use for the batch session

    EffectInstance effect

    The effect to use for the batch session

    System.Int32 stencilValue

    The value of the stencil buffer to take as reference for the batch session


    Begin(GraphicsContext, SpriteSortMode, EffectInstance)

    Begins a sprite batch operation using deferred sort and default state objects (BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise).

    public void Begin(GraphicsContext graphicsContext, SpriteSortMode sortMode, EffectInstance effect)
    Parameters
    Type Name Description
    GraphicsContext graphicsContext

    The graphics context to use.

    SpriteSortMode sortMode

    The sprite drawing order to use for the batch session

    EffectInstance effect

    The effect to use for the batch session


    Begin(GraphicsContext, SpriteSortMode, Nullable<BlendStateDescription>, SamplerState, Nullable<DepthStencilStateDescription>, Nullable<RasterizerStateDescription>, EffectInstance, Int32)

    Begins a sprite batch rendering using the specified sorting mode and blend state, sampler, depth stencil and rasterizer state objects, plus a custom effect. Passing null for any of the state objects selects the default default state objects (BlendState.AlphaBlend, DepthStencilState.Default, RasterizerState.CullCounterClockwise, SamplerState.LinearClamp). Passing a null effect selects the default SpriteBatch Class shader.

    public void Begin(GraphicsContext graphicsContext, SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendStateDescription? blendState = null, SamplerState samplerState = null, DepthStencilStateDescription? depthStencilState = null, RasterizerStateDescription? rasterizerState = null, EffectInstance effect = null, int stencilValue = 0)
    Parameters
    Type Name Description
    GraphicsContext graphicsContext

    The graphics context to use.

    SpriteSortMode sortMode

    The sprite drawing order to use for the batch session

    System.Nullable<BlendStateDescription> blendState

    The blending state to use for the batch session

    SamplerState samplerState

    The sampling state to use for the batch session

    System.Nullable<DepthStencilStateDescription> depthStencilState

    The depth stencil state to use for the batch session

    System.Nullable<RasterizerStateDescription> rasterizerState

    The rasterizer state to use for the batch session

    EffectInstance effect

    The effect to use for the batch session

    System.Int32 stencilValue

    The value of the stencil buffer to take as reference for the batch session


    CalculateDefaultProjection(Vector3)

    Calculate the default projection matrix for the provided virtual resolution.

    public static Matrix CalculateDefaultProjection(Vector3 virtualResolution)
    Parameters
    Type Name Description
    Vector3 virtualResolution
    Returns
    Type Description
    Matrix

    The default projection matrix for the provided virtual resolution

    Remarks

    The sprite batch default projection is an orthogonal matrix such as (0,0) is the Top/Left corner of the screen and (VirtualResolution.X, VirtualResolution.Y) is the Bottom/Right corner of the screen.


    CalculateDefaultProjection(ref Vector3, out Matrix)

    Calculate the default projection matrix for the provided virtual resolution.

    public static void CalculateDefaultProjection(ref Vector3 virtualResolution, out Matrix projection)
    Parameters
    Type Name Description
    Vector3 virtualResolution
    Matrix projection

    Draw(Texture, RectangleF, Color4, Color4)

    Adds a sprite to a batch of sprites for rendering using the specified texture, destination rectangle, and color.

    public void Draw(Texture texture, RectangleF destinationRectangle, Color4 color, Color4 colorAdd = default(Color4))
    Parameters
    Type Name Description
    Texture texture

    A texture.

    RectangleF destinationRectangle

    A rectangle that specifies (in screen coordinates) the destination for drawing the sprite.

    Color4 color

    The color to tint a sprite. Use Color.White for full color with no tinting.

    Color4 colorAdd
    Remarks

    Before making any calls to Draw, you must call Begin. Once all calls to Draw are complete, call End.


    Draw(Texture, RectangleF, Nullable<RectangleF>, Color4, Single, Vector2, SpriteEffects, ImageOrientation, Single, Color4, SwizzleMode)

    Adds a sprite to a batch of sprites for rendering using the specified texture, destination rectangle, source rectangle, color, rotation, origin, effects and layer.

    public void Draw(Texture texture, RectangleF destinationRectangle, RectangleF? sourceRectangle, Color4 color, float rotation, Vector2 origin, SpriteEffects effects = SpriteEffects.None, ImageOrientation orientation = ImageOrientation.AsIs, float layerDepth = 0F, Color4 colorAdd = default(Color4), SwizzleMode swizzle = SwizzleMode.None)
    Parameters
    Type Name Description
    Texture texture

    A texture.

    RectangleF destinationRectangle

    A rectangle that specifies (in screen coordinates) the destination for drawing the sprite. If this rectangle is not the same size as the source rectangle, the sprite will be scaled to fit.

    System.Nullable<RectangleF> sourceRectangle

    A rectangle that specifies (in texels) the source texels from a texture. Use null to draw the entire texture.

    Color4 color

    The color to tint a sprite. Use Color.White for full color with no tinting.

    System.Single rotation

    Specifies the angle (in radians) to rotate the sprite about its center.

    Vector2 origin

    The sprite origin in the texture in pixels (dependent of image orientation). Default value is (0,0) which represents the upper-left corner.

    SpriteEffects effects

    Effects to apply.

    ImageOrientation orientation

    The source image orientation

    System.Single layerDepth

    The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.

    Color4 colorAdd
    SwizzleMode swizzle

    Draw(Texture, Vector2)

    Adds a sprite to a batch of sprites for rendering using the specified texture, position and color.

    public void Draw(Texture texture, Vector2 position)
    Parameters
    Type Name Description
    Texture texture

    A texture.

    Vector2 position

    The location (in screen coordinates) to draw the sprite.


    Draw(Texture, Vector2, Color, Color4)

    Adds a sprite to a batch of sprites for rendering using the specified texture, position and color.

    public void Draw(Texture texture, Vector2 position, Color color, Color4 colorAdd = default(Color4))
    Parameters
    Type Name Description
    Texture texture

    A texture.

    Vector2 position

    The location (in screen coordinates) to draw the sprite.

    Color color

    The color to tint a sprite. Use Color.White for full color with no tinting.

    Color4 colorAdd

    Draw(Texture, Vector2, Color4, Single, Vector2, Vector2, SpriteEffects, ImageOrientation, Single)

    Adds a sprite to a batch of sprites for rendering using the specified texture, position, source rectangle, color, rotation, origin, scale, effects, and layer.

    public void Draw(Texture texture, Vector2 position, Color4 color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects = SpriteEffects.None, ImageOrientation orientation = ImageOrientation.AsIs, float layerDepth = 0F)
    Parameters
    Type Name Description
    Texture texture

    A texture.

    Vector2 position

    The location (in screen coordinates) to draw the sprite.

    Color4 color

    The color to tint a sprite. Use Color.White for full color with no tinting.

    System.Single rotation

    Specifies the angle (in radians) to rotate the sprite about its center.

    Vector2 origin

    The sprite origin in the texture in pixels (dependent of image orientation). Default value is (0,0) which represents the upper-left corner.

    Vector2 scale

    Scale factor.

    SpriteEffects effects

    Effects to apply.

    ImageOrientation orientation

    The source image orientation

    System.Single layerDepth

    The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.


    Draw(Texture, Vector2, Color4, Single, Vector2, Single, SpriteEffects, ImageOrientation, Single)

    Adds a sprite to a batch of sprites for rendering using the specified texture, position, source rectangle, color, rotation, origin, scale, effects, and layer.

    public void Draw(Texture texture, Vector2 position, Color4 color, float rotation, Vector2 origin, float scale = 1F, SpriteEffects effects = SpriteEffects.None, ImageOrientation orientation = ImageOrientation.AsIs, float layerDepth = 0F)
    Parameters
    Type Name Description
    Texture texture

    A texture.

    Vector2 position

    The location (in screen coordinates) to draw the sprite.

    Color4 color

    The color to tint a sprite. Use Color.White for full color with no tinting.

    System.Single rotation

    Specifies the angle (in radians) to rotate the sprite about its center.

    Vector2 origin

    The sprite origin in the texture in pixels (dependent of image orientation). Default value is (0,0) which represents the upper-left corner.

    System.Single scale

    Scale factor.

    SpriteEffects effects

    Effects to apply.

    ImageOrientation orientation

    The source image orientation

    System.Single layerDepth

    The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.


    Draw(Texture, Vector2, Nullable<RectangleF>, Color4, Color4)

    Adds a sprite to a batch of sprites for rendering using the specified texture, position, source rectangle, and color.

    public void Draw(Texture texture, Vector2 position, RectangleF? sourceRectangle, Color4 color, Color4 colorAdd = default(Color4))
    Parameters
    Type Name Description
    Texture texture

    A texture.

    Vector2 position

    The location (in screen coordinates) to draw the sprite.

    System.Nullable<RectangleF> sourceRectangle

    A rectangle that specifies (in texels) the source texels from a texture. Use null to draw the entire texture.

    Color4 color

    The color to tint a sprite. Use Color.White for full color with no tinting.

    Color4 colorAdd

    Draw(Texture, Vector2, Nullable<RectangleF>, Color4, Single, Vector2, Vector2, SpriteEffects, ImageOrientation, Single, Color4)

    Adds a sprite to a batch of sprites for rendering using the specified texture, position, source rectangle, color, rotation, origin, scale, effects, and layer.

    public void Draw(Texture texture, Vector2 position, RectangleF? sourceRectangle, Color4 color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects = SpriteEffects.None, ImageOrientation orientation = ImageOrientation.AsIs, float layerDepth = 0F, Color4 colorAdd = default(Color4))
    Parameters
    Type Name Description
    Texture texture

    A texture.

    Vector2 position

    The location (in screen coordinates) to draw the sprite.

    System.Nullable<RectangleF> sourceRectangle

    A rectangle that specifies (in texels) the source texels from a texture. Use null to draw the entire texture.

    Color4 color

    The color to tint a sprite. Use Color.White for full color with no tinting.

    System.Single rotation

    Specifies the angle (in radians) to rotate the sprite about its center.

    Vector2 origin

    The sprite origin in the texture in pixels (dependent of image orientation). Default value is (0,0) which represents the upper-left corner.

    Vector2 scale

    Scale factor.

    SpriteEffects effects

    Effects to apply.

    ImageOrientation orientation

    The source image orientation

    System.Single layerDepth

    The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.

    Color4 colorAdd

    Draw(Texture, Vector2, Nullable<RectangleF>, Color4, Single, Vector2, Single, SpriteEffects, ImageOrientation, Single, Color4, SwizzleMode)

    Adds a sprite to a batch of sprites for rendering using the specified texture, position, source rectangle, color, rotation, origin, scale, effects, and layer.

    public void Draw(Texture texture, Vector2 position, RectangleF? sourceRectangle, Color4 color, float rotation, Vector2 origin, float scale = 1F, SpriteEffects effects = SpriteEffects.None, ImageOrientation orientation = ImageOrientation.AsIs, float layerDepth = 0F, Color4 colorAdd = default(Color4), SwizzleMode swizzle = SwizzleMode.None)
    Parameters
    Type Name Description
    Texture texture

    A texture.

    Vector2 position

    The location (in screen coordinates) to draw the sprite.

    System.Nullable<RectangleF> sourceRectangle

    A rectangle that specifies (in texels) the source texels from a texture. Use null to draw the entire texture.

    Color4 color

    The color to tint a sprite. Use Color4.White for full color with no tinting.

    System.Single rotation

    Specifies the angle (in radians) to rotate the sprite about its center.

    Vector2 origin

    The sprite origin in the texture in pixels (dependent of image orientation). Default value is (0,0) which represents the upper-left corner.

    System.Single scale

    Scale factor.

    SpriteEffects effects

    Effects to apply.

    ImageOrientation orientation

    The source image orientation

    System.Single layerDepth

    The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.

    Color4 colorAdd
    SwizzleMode swizzle

    DrawString(SpriteFont, String, Vector2, Color4, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, and color.

    public void DrawString(SpriteFont spriteFont, string text, Vector2 position, Color4 color, TextAlignment alignment = TextAlignment.Left)
    Parameters
    Type Name Description
    SpriteFont spriteFont

    A font for displaying text.

    System.String text

    A text string.

    Vector2 position

    The location (in screen coordinates) to draw the sprite.

    Color4 color

    The color to tint a sprite. Use Color.White for full color with no tinting.

    TextAlignment alignment

    Describes how to align the text to draw


    DrawString(SpriteFont, String, Vector2, Color4, Single, Vector2, Vector2, SpriteEffects, Single, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, color, rotation, origin, scale, effects and layer.

    public void DrawString(SpriteFont spriteFont, string text, Vector2 position, Color4 color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth, TextAlignment alignment)
    Parameters
    Type Name Description
    SpriteFont spriteFont

    A font for displaying text.

    System.String text

    A text string.

    Vector2 position

    The location (in screen coordinates) to draw the sprite.

    Color4 color

    The color to tint a sprite. Use Color.White for full color with no tinting.

    System.Single rotation

    Specifies the angle (in radians) to rotate the sprite about its center.

    Vector2 origin

    The sprite origin in virtual pixels; the default is (0,0) which represents the upper-left corner.

    Vector2 scale

    Scale factor.

    SpriteEffects effects

    Effects to apply.

    System.Single layerDepth

    The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.

    TextAlignment alignment

    Describes how to align the text to draw


    DrawString(SpriteFont, String, Single, Vector2, Color4, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, and color.

    public void DrawString(SpriteFont spriteFont, string text, float fontSize, Vector2 position, Color4 color, TextAlignment alignment = TextAlignment.Left)
    Parameters
    Type Name Description
    SpriteFont spriteFont

    A font for displaying text.

    System.String text

    A text string.

    System.Single fontSize

    The font size in pixels (ignored in the case of static fonts)

    Vector2 position

    The location (in screen coordinates) to draw the sprite.

    Color4 color

    The color to tint a sprite. Use Color.White for full color with no tinting.

    TextAlignment alignment

    Describes how to align the text to draw


    DrawString(SpriteFont, String, Single, Vector2, Color4, Single, Vector2, Vector2, SpriteEffects, Single, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, color, rotation, origin, scale, effects and layer.

    public void DrawString(SpriteFont spriteFont, string text, float fontSize, Vector2 position, Color4 color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth, TextAlignment alignment)
    Parameters
    Type Name Description
    SpriteFont spriteFont

    A font for displaying text.

    System.String text

    A text string.

    System.Single fontSize

    The font size in pixels (ignored in the case of static fonts)

    Vector2 position

    The location (in screen coordinates) to draw the sprite.

    Color4 color

    The color to tint a sprite. Use Color.White for full color with no tinting.

    System.Single rotation

    Specifies the angle (in radians) to rotate the sprite about its center.

    Vector2 origin

    The sprite origin in virtual pixels; the default is (0,0) which represents the upper-left corner.

    Vector2 scale

    Scale factor.

    SpriteEffects effects

    Effects to apply.

    System.Single layerDepth

    The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.

    TextAlignment alignment

    Describes how to align the text to draw


    DrawString(SpriteFont, StringBuilder, Vector2, Color4, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, and color.

    public void DrawString(SpriteFont spriteFont, StringBuilder text, Vector2 position, Color4 color, TextAlignment alignment = TextAlignment.Left)
    Parameters
    Type Name Description
    SpriteFont spriteFont

    A font for displaying text.

    System.Text.StringBuilder text

    Text string.

    Vector2 position

    The location (in screen coordinates) to draw the sprite.

    Color4 color

    The color to tint a sprite. Use Color.White for full color with no tinting.

    TextAlignment alignment

    Describes how to align the text to draw


    DrawString(SpriteFont, StringBuilder, Vector2, Color4, Single, Vector2, Vector2, SpriteEffects, Single, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, color, rotation, origin, scale, effects and layer.

    public void DrawString(SpriteFont spriteFont, StringBuilder text, Vector2 position, Color4 color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth, TextAlignment alignment)
    Parameters
    Type Name Description
    SpriteFont spriteFont

    A font for displaying text.

    System.Text.StringBuilder text

    Text string.

    Vector2 position

    The location (in screen coordinates) to draw the sprite.

    Color4 color

    The color to tint a sprite. Use Color.White for full color with no tinting.

    System.Single rotation

    Specifies the angle (in radians) to rotate the sprite about its center.

    Vector2 origin

    The sprite origin in virtual pixels; the default is (0,0) which represents the upper-left corner.

    Vector2 scale

    Scale factor.

    SpriteEffects effects

    Effects to apply.

    System.Single layerDepth

    The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.

    TextAlignment alignment

    Describes how to align the text to draw


    DrawString(SpriteFont, StringBuilder, Single, Vector2, Color4, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, and color.

    public void DrawString(SpriteFont spriteFont, StringBuilder text, float fontSize, Vector2 position, Color4 color, TextAlignment alignment = TextAlignment.Left)
    Parameters
    Type Name Description
    SpriteFont spriteFont

    A font for displaying text.

    System.Text.StringBuilder text

    Text string.

    System.Single fontSize

    The font size in pixels (ignored in the case of static fonts)

    Vector2 position

    The location (in screen coordinates) to draw the sprite.

    Color4 color

    The color to tint a sprite. Use Color.White for full color with no tinting.

    TextAlignment alignment

    Describes how to align the text to draw


    DrawString(SpriteFont, StringBuilder, Single, Vector2, Color4, Single, Vector2, Vector2, SpriteEffects, Single, TextAlignment)

    Adds a string to a batch of sprites for rendering using the specified font, text, position, color, rotation, origin, scale, effects and layer.

    public void DrawString(SpriteFont spriteFont, StringBuilder text, float fontSize, Vector2 position, Color4 color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth, TextAlignment alignment)
    Parameters
    Type Name Description
    SpriteFont spriteFont

    A font for displaying text.

    System.Text.StringBuilder text

    Text string.

    System.Single fontSize

    The font size in pixels (ignored in the case of static fonts)

    Vector2 position

    The location (in screen coordinates) to draw the sprite.

    Color4 color

    The color to tint a sprite. Use Color.White for full color with no tinting.

    System.Single rotation

    Specifies the angle (in radians) to rotate the sprite about its center.

    Vector2 origin

    The sprite origin in virtual pixels; the default is (0,0) which represents the upper-left corner.

    Vector2 scale

    Scale factor.

    SpriteEffects effects

    Effects to apply.

    System.Single layerDepth

    The depth of a layer. By default, 0 represents the front layer and 1 represents a back layer. Use SpriteSortMode if you want sprites to be sorted during drawing.

    TextAlignment alignment

    Describes how to align the text to draw


    MeasureString(SpriteFont, String, Nullable<Vector2>)

    Measure the size of the given text in virtual pixels depending on the target size.

    public Vector2 MeasureString(SpriteFont spriteFont, string text, Vector2? targetSize = null)
    Parameters
    Type Name Description
    SpriteFont spriteFont

    The font used to draw the text.

    System.String text

    The text to measure.

    System.Nullable<Vector2> targetSize

    The size of the target to render in. If null, the size of the window back buffer is used.

    Returns
    Type Description
    Vector2

    The size of the text in virtual pixels.

    Exceptions
    Type Condition
    System.ArgumentNullException

    The provided sprite font is null.


    MeasureString(SpriteFont, String, Single, Nullable<Vector2>)

    Measure the size of the given text in virtual pixels depending on the target size.

    public Vector2 MeasureString(SpriteFont spriteFont, string text, float fontSize, Vector2? targetSize = null)
    Parameters
    Type Name Description
    SpriteFont spriteFont

    The font used to draw the text.

    System.String text

    The text to measure.

    System.Single fontSize

    The font size (in pixels) used to draw the text.

    System.Nullable<Vector2> targetSize

    The size of the target to render in. If null, the size of the window back buffer is used.

    Returns
    Type Description
    Vector2

    The size of the text in virtual pixels.

    Exceptions
    Type Condition
    System.ArgumentNullException

    The provided sprite font is null.


    PrepareForRendering()

    protected override void PrepareForRendering()
    Overrides
    Stride.Graphics.BatchBase<Stride.Graphics.SpriteBatch.SpriteDrawInfo>.PrepareForRendering()

    UpdateBufferValuesFromElementInfo(ref BatchBase<SpriteBatch.SpriteDrawInfo>.ElementInfo, IntPtr, IntPtr, Int32)

    protected override void UpdateBufferValuesFromElementInfo(ref BatchBase<SpriteBatch.SpriteDrawInfo>.ElementInfo elementInfo, IntPtr vertexPtr, IntPtr indexPtr, int vertexOffset)
    Parameters
    Type Name Description
    BatchBase.ElementInfo<> elementInfo
    System.IntPtr vertexPtr
    System.IntPtr indexPtr
    System.Int32 vertexOffset
    Overrides
    Stride.Graphics.BatchBase<Stride.Graphics.SpriteBatch.SpriteDrawInfo>.UpdateBufferValuesFromElementInfo(Stride.Graphics.BatchBase.ElementInfo<>, System.IntPtr, System.IntPtr, System.Int32)

    Inherited Members

    BatchBase<SpriteBatch.SpriteDrawInfo>.ResourceContextPool
    BatchBase<SpriteBatch.SpriteDrawInfo>.ResourceContext
    BatchBase<SpriteBatch.SpriteDrawInfo>.mutablePipeline
    BatchBase<SpriteBatch.SpriteDrawInfo>.graphicsDevice
    BatchBase<SpriteBatch.SpriteDrawInfo>.blendState
    BatchBase<SpriteBatch.SpriteDrawInfo>.rasterizerState
    BatchBase<SpriteBatch.SpriteDrawInfo>.samplerState
    BatchBase<SpriteBatch.SpriteDrawInfo>.depthStencilState
    BatchBase<SpriteBatch.SpriteDrawInfo>.stencilReferenceValue
    BatchBase<SpriteBatch.SpriteDrawInfo>.sortMode
    BatchBase<SpriteBatch.SpriteDrawInfo>.Effect
    BatchBase<SpriteBatch.SpriteDrawInfo>.GraphicsContext
    BatchBase<SpriteBatch.SpriteDrawInfo>.DefaultEffect
    BatchBase<SpriteBatch.SpriteDrawInfo>.DefaultEffectSRgb
    BatchBase<SpriteBatch.SpriteDrawInfo>.TextureComparer
    BatchBase<SpriteBatch.SpriteDrawInfo>.BackToFrontComparer
    BatchBase<SpriteBatch.SpriteDrawInfo>.FrontToBackComparer
    BatchBase<SpriteBatch.SpriteDrawInfo>.Destroy()
    BatchBase<SpriteBatch.SpriteDrawInfo>.Parameters
    BatchBase<SpriteBatch.SpriteDrawInfo>.Begin(GraphicsContext, EffectInstance, SpriteSortMode, Nullable<BlendStateDescription>, SamplerState, Nullable<DepthStencilStateDescription>, Nullable<RasterizerStateDescription>, Int32)
    BatchBase<SpriteBatch.SpriteDrawInfo>.CheckBeginHasBeenCalled(String)
    BatchBase<SpriteBatch.SpriteDrawInfo>.CheckEndHasBeenCalled(String)
    BatchBase<SpriteBatch.SpriteDrawInfo>.End()
    BatchBase<SpriteBatch.SpriteDrawInfo>.Draw(Texture, BatchBase.ElementInfo<>)
    ComponentBase.Tags
    ComponentBase.Name
    ComponentBase.ICollectorHolder.Collector
    ComponentBase.OnNameChanged()
    ComponentBase.ToString()
    DisposeBase.Dispose()
    DisposeBase.IsDisposed
    DisposeBase.IReferencable.ReferenceCount
    DisposeBase.IReferencable.AddReference()
    DisposeBase.IReferencable.Release()
    DisposeBase.OnAddReference()
    DisposeBase.OnReleaseReference()

    Extension Methods

    ComponentBaseExtensions.DisposeBy<T>(T, ICollectorHolder)
    ComponentBaseExtensions.RemoveDisposeBy<T>(T, ICollectorHolder)
    • Improve this Doc
    • View Source
    In This Article

    Back to top

    Copyright © 2019-2021 .NET Foundation and Contributors
    Supported by the .NET Foundation