Table of Contents

Method AddSprites

Namespace
PaintDotNet.Direct2D1
Assembly
PaintDotNet.Windows.dll

AddSprites(ISpriteBatch, ReadOnlySpan<RectFloat>, ReadOnlySpan<RectInt32>, ReadOnlySpan<ColorRgba128Float>, ReadOnlySpan<Matrix3x2Float>)

Adds the given sprites to the end of this sprite batch. The number of sprites is governed by the length of the destinationRectangles parameter. You may use a 1-length span for the other spans to apply the same value for that property to each of the sprites. You may use a 0-length span for the other spans to use the default value associated with those properties, which can reduce memory usage and increase performance.

public static void AddSprites(this ISpriteBatch spriteBatch, ReadOnlySpan<RectFloat> destinationRectangles, ReadOnlySpan<RectInt32> sourceRectangles, ReadOnlySpan<ColorRgba128Float> colors, ReadOnlySpan<Matrix3x2Float> transforms)

Parameters

spriteBatch ISpriteBatch

The sprite batch object.

destinationRectangles ReadOnlySpan<RectFloat>

The destination rectangles specifying where to draw the sprites.

sourceRectangles ReadOnlySpan<RectInt32>

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 if RectInt32.LogicallyInfinite is used. If this span is empty, Direct2D will use the entire source bitmap for all of the added sprites.

colors ReadOnlySpan<ColorRgba128Float>

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 span is empty, then Direct2D will not change the color of any of the added sprites.

transforms ReadOnlySpan<Matrix3x2Float>

The transforms to apply to each sprite's destination recangle. Direct2D will not transform the destination rectangle of any sprites that are assigned a null value. If this span is empty then Direct2D will not transform the destination rectangle of any of the added sprites.

Remarks

Always use an empty span 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).