Table of Contents

Class SpriteBatch

Namespace
SharpDX.Direct2D1
Assembly
SharpDX.Direct2D1.dll
[Guid("4dc583bf-3a10-438a-8722-e9765224f1f1")]
public class SpriteBatch : Resource
Inheritance
SpriteBatch
Inherited Members

Constructors

SpriteBatch(DeviceContext3)

Initializes a new instance of the SpriteBatch.

public SpriteBatch(DeviceContext3 context3)

Parameters

context3 DeviceContext3

SpriteBatch(nint)

public SpriteBatch(nint nativePtr)

Parameters

nativePtr nint

Properties

SpriteCount

Retrieves the number of sprites in this sprite batch.

public int SpriteCount { get; }

Property Value

int

Methods

AddSprites(int, RawRectangleF[], RawRectangle[], RawColor4[], RawMatrix3x2[], int, int, int, int)

Adds the given sprites to the end of this sprite batch.

public void AddSprites(int spriteCount, RawRectangleF[] destinationRectangles, RawRectangle[] sourceRectangles, RawColor4[] colors, RawMatrix3x2[] transforms, int destinationRectanglesStride, int sourceRectanglesStride, int colorsStride, int transformsStride)

Parameters

spriteCount int

The number of sprites to be added. This determines how many strides into each given array Direct2D will read.

destinationRectangles RawRectangleF[]

A reference to an array containing the destination rectangles specifying where to draw the sprites on the destination device context.

sourceRectangles RawRectangle[]

A reference to an array containing the source rectangles specifying the regions of the source bitmap to draw as sprites. Direct2D will use the entire source bitmap for sprites that are assigned a null value or the InfiniteRectU. If this parameter is omitted entirely or set to a null value, then Direct2D will use the entire source bitmap for all the added sprites.

colors RawColor4[]

A reference to an array containing the colors to apply to each sprite. The output color is the result of component-wise multiplication of the source bitmap color and the provided color. The output color is not clamped.

Direct2D will not change the color of sprites that are assigned a null value. If this parameter is omitted entirely or set to a null value, then Direct2D will not change the color of any of the added sprites.

transforms RawMatrix3x2[]

A reference to an array containing the transforms to apply to each sprite?s destination rectangle.

Direct2D will not transform the destination rectangle of any sprites that are assigned a null value. If this parameter is omitted entirely or set to a null value, then Direct2D will not transform the destination rectangle of any of the added sprites.

destinationRectanglesStride int

Specifies the distance, in bytes, between each rectangle in the destinationRectangles array. If you provide a stride of 0, then the same destination rectangle will be used for each added sprite.

sourceRectanglesStride int

Specifies the distance, in bytes, between each rectangle in the sourceRectangles array (if that array is given). If you provide a stride of 0, then the same source rectangle will be used for each added sprite.

colorsStride int

Specifies the distance, in bytes, between each color in the colors array (if that array is given). If you provide a stride of 0, then the same color will be used for each added sprite.

transformsStride int

Specifies the distance, in bytes, between each transform in the transforms array (if that array is given). If you provide a stride of 0, then the same transform will be used for each added sprite.

Remarks

In Direct2D, a sprite is defined by four properties: a destination rectangle, a source rectangle, a color, and a transform. Destination rectangles are mandatory, but the remaining properties are optional.

Note??Always omit or pass a null value for properties you do not wish to use. This allows Direct2D to avoid storing values for those properties and to skip their handling entirely, which improves drawing speed. For example, suppose you have a batch of 500 sprites, and you do not wish to transform any of their destination rectangles. Rather than passing an array of identity matrices, simply omit the transforms parameter. This allows Direct2D to avoid storing any transforms and will yield the fastest drawing performance. On the other hand, if any sprite in the batch has any value set for a property, then internally Direct2D must allocate space for that property array and assign every sprite a value for that property (even if it?s just the default value).?

Clear()

Removes all sprites from this sprite batch.

public void Clear()

GetSprites(int, int, RawRectangleF[], RawRectangle[], RawColor4[], RawMatrix3x2[])

Retrieves the specified subset of sprites from this sprite batch. For the best performance, use nullptr for properties that you do not need to retrieve.

public void GetSprites(int startIndex, int spriteCount, RawRectangleF[] destinationRectangles, RawRectangle[] sourceRectangles, RawColor4[] colors, RawMatrix3x2[] transforms)

Parameters

startIndex int

The index of the first sprite in this sprite batch to retrieve.

spriteCount int

The number of sprites to retrieve.

destinationRectangles RawRectangleF[]

When this method returns, contains a reference to an array containing the destination rectangles for the retrieved sprites.

sourceRectangles RawRectangle[]

When this method returns, contains a reference to an array containing the source rectangles for the retrieved sprites.

The InfiniteRectU is returned for any sprites that were not assigned a source rectangle.

colors RawColor4[]

When this method returns, contains a reference to an array containing the colors to be applied to the retrieved sprites.

The color {1.0f, 1.0f, 1.0f, 1.0f} is returned for any sprites that were not assigned a color.

transforms RawMatrix3x2[]

When this method returns, contains a reference to an array containing the transforms to be applied to the retrieved sprites.

The identity matrix is returned for any sprites that were not assigned a transform.

SetSprites(int, int, RawRectangleF[], RawRectangle[], RawColor4[], RawMatrix3x2[], int, int, int, int)

Updates the properties of the specified sprites in this sprite batch. Providing a null value for any property will leave that property unmodified for that sprite.

public void SetSprites(int startIndex, int spriteCount, RawRectangleF[] destinationRectangles, RawRectangle[] sourceRectangles, RawColor4[] colors, RawMatrix3x2[] transforms, int destinationRectanglesStride, int sourceRectanglesStride, int colorsStride, int transformsStride)

Parameters

startIndex int

The index of the first sprite in this sprite batch to update.

spriteCount int

The number of sprites to update with new properties. This determines how many strides into each given array Direct2D will read.

destinationRectangles RawRectangleF[]

A reference to an array containing the destination rectangles specifying where to draw the sprites on the destination device context.

sourceRectangles RawRectangle[]

A reference to an array containing the source rectangles specifying the regions of the source bitmap to draw as sprites.

Direct2D will use the entire source bitmap for sprites that are assigned a null value or the InfiniteRectU. If this parameter is omitted entirely or set to a null value, then Direct2D will use the entire source bitmap for all the updated sprites.

colors RawColor4[]

A reference to an array containing the colors to apply to each sprite. The output color is the result of component-wise multiplication of the source bitmap color and the provided color. The output color is not clamped.

Direct2D will not change the color of sprites that are assigned a null value. If this parameter is omitted entirely or set to a null value, then Direct2D will not change the color of any of the updated sprites.

transforms RawMatrix3x2[]

A reference to an array containing the transforms to apply to each sprite?s destination rectangle.

Direct2D will not transform the destination rectangle of any sprites that are assigned a null value. If this parameter is omitted entirely or set to a null value, then Direct2D will not transform the destination rectangle of any of the updated sprites.

destinationRectanglesStride int

Specifies the distance, in bytes, between each rectangle in the destinationRectangles array. If you provide a stride of 0, then the same destination rectangle will be used for each updated sprite.

sourceRectanglesStride int

Specifies the distance, in bytes, between each rectangle in the sourceRectangles array (if that array is given). If you provide a stride of 0, then the same source rectangle will be used for each updated sprite.

colorsStride int

Specifies the distance, in bytes, between each color in the colors array (if that array is given). If you provide a stride of 0, then the same color will be used for each updated sprite.

transformsStride int

Specifies the distance, in bytes, between each transform in the transforms array (if that array is given). If you provide a stride of 0, then the same transform will be used for each updated sprite.

Operators

explicit operator SpriteBatch(nint)

public static explicit operator SpriteBatch(nint nativePtr)

Parameters

nativePtr nint

Returns

SpriteBatch