Table of Contents

Class SpriteBatchExtensions

Namespace
MLEM.Graphics
Assembly
MLEM.dll

A set of extensions for dealing with Microsoft.Xna.Framework.Graphics.SpriteBatch

public static class SpriteBatchExtensions
Inheritance
SpriteBatchExtensions
Inherited Members

Methods

Add(StaticSpriteBatch, Texture2D, RectangleF, Color)

Adds an item to this batch. Note that this batch needs to currently be batching, meaning BeginBatch(SpriteSortMode?) has to have been called previously.

public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Color color)

Parameters

batch StaticSpriteBatch
texture Texture2D

A texture.

destinationRectangle RectangleF

The drawing bounds on screen.

color Color

A color mask.

Returns

StaticSpriteBatch.Item

The StaticSpriteBatch.Item that was created from the added data

Add(StaticSpriteBatch, Texture2D, RectangleF, Rectangle?, Color)

Adds an item to this batch. Note that this batch needs to currently be batching, meaning BeginBatch(SpriteSortMode?) has to have been called previously.

public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Rectangle? sourceRectangle, Color color)

Parameters

batch StaticSpriteBatch
texture Texture2D

A texture.

destinationRectangle RectangleF

The drawing bounds on screen.

sourceRectangle Rectangle?

An optional region on the texture which will be rendered. If null - draws full texture.

color Color

A color mask.

Returns

StaticSpriteBatch.Item

The StaticSpriteBatch.Item that was created from the added data

Add(StaticSpriteBatch, Texture2D, RectangleF, Rectangle?, Color, float, Vector2, SpriteEffects, float)

Adds an item to this batch. Note that this batch needs to currently be batching, meaning BeginBatch(SpriteSortMode?) has to have been called previously.

public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth)

Parameters

batch StaticSpriteBatch
texture Texture2D

A texture.

destinationRectangle RectangleF

The drawing bounds on screen.

sourceRectangle Rectangle?

An optional region on the texture which will be rendered. If null - draws full texture.

color Color

A color mask.

rotation float

A rotation of this sprite.

origin Vector2

Center of the rotation. 0,0 by default.

effects SpriteEffects

Modificators for drawing. Can be combined.

layerDepth float

A depth of the layer of this sprite.

Returns

StaticSpriteBatch.Item

The StaticSpriteBatch.Item that was created from the added data

Draw(SpriteBatch, Texture2D, RectangleF, Color)

Submit a sprite for drawing in the current batch.

public static void Draw(this SpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Color color)

Parameters

batch SpriteBatch

The sprite batch to draw with.

texture Texture2D

A texture.

destinationRectangle RectangleF

The drawing bounds on screen.

color Color

A color mask.

Draw(SpriteBatch, Texture2D, RectangleF, Rectangle?, Color)

Submit a sprite for drawing in the current batch.

public static void Draw(this SpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Rectangle? sourceRectangle, Color color)

Parameters

batch SpriteBatch

The sprite batch to draw with.

texture Texture2D

A texture.

destinationRectangle RectangleF

The drawing bounds on screen.

sourceRectangle Rectangle?

An optional region on the texture which will be rendered. If null - draws full texture.

color Color

A color mask.

Draw(SpriteBatch, Texture2D, RectangleF, Rectangle?, Color, float, Vector2, SpriteEffects, float)

Submit a sprite for drawing in the current batch.

public static void Draw(this SpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth)

Parameters

batch SpriteBatch

The sprite batch to draw with.

texture Texture2D

A texture.

destinationRectangle RectangleF

The drawing bounds on screen.

sourceRectangle Rectangle?

An optional region on the texture which will be rendered. If null - draws full texture.

color Color

A color mask.

rotation float

A rotation of this sprite.

origin Vector2

Center of the rotation. 0,0 by default.

effects SpriteEffects

Modificators for drawing. Can be combined.

layerDepth float

A depth of the layer of this sprite.

GenerateCircleTexture(SpriteBatch, Color, int)

Generates a texture with the given size that contains a circle. The circle's center will be the center of the texture, and the circle will lead up to the edges of the texture. This texture is automatically disposed of when the batch is disposed.

public static Texture2D GenerateCircleTexture(this SpriteBatch batch, Color color, int size)

Parameters

batch SpriteBatch

The sprite batch

color Color

The color of the texture

size int

The width and height of the texture, and the diameter of the circle

Returns

Texture2D

A new texture with the given data

GenerateGradientTexture(SpriteBatch, Color, Color, Color, Color, int, int)

Generates a texture with the given size that contains a gradient between the four specified corner colors. If the same color is specified for two pairs of corners, a horizontal, vertical or diagonal gradient can be achieved. This texture is automatically disposed of when the batch is disposed.

public static Texture2D GenerateGradientTexture(this SpriteBatch batch, Color topLeft, Color topRight, Color bottomLeft, Color bottomRight, int width = 256, int height = 256)

Parameters

batch SpriteBatch

The sprite batch

topLeft Color

The color of the texture's top left corner

topRight Color

The color of the texture's top right corner

bottomLeft Color

The color of the texture's bottom left corner

bottomRight Color

The color of the texture's bottom right corner

width int

The width of the resulting texture, or 256 by default

height int

The height of the resulting texture, or 256 by default

Returns

Texture2D

A new texture with the given data

GenerateSquareTexture(SpriteBatch, Color)

Generates a 1x1 texture with the given color. This texture is automatically disposed of when the batch is disposed.

public static Texture2D GenerateSquareTexture(this SpriteBatch batch, Color color)

Parameters

batch SpriteBatch

The sprite batch

color Color

The color of the texture

Returns

Texture2D

A new texture with the given data

GenerateTexture(SpriteBatch, Color, Color?)

Generates a NinePatch that has a texture with a given color and outline color. This texture is automatically disposed of when the batch is disposed.

public static NinePatch GenerateTexture(this SpriteBatch batch, Color color, Color? outlineColor = null)

Parameters

batch SpriteBatch

The sprite batch

color Color

The fill color of the texture

outlineColor Color?

The outline color of the texture

Returns

NinePatch

A NinePatch containing a 3x3 texture with an outline

GetBlankTexture(SpriteBatch)

Returns a 1x1 pixel white texture that can be used for drawing solid color shapes. This texture is automatically disposed of when the batch is disposed.

public static Texture2D GetBlankTexture(this SpriteBatch batch)

Parameters

batch SpriteBatch

The sprite batch

Returns

Texture2D

A 1x1 pixel white texture