Class SpriteBatchExtensions
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
StaticSpriteBatchtexture
Texture2DA texture.
destinationRectangle
RectangleFThe drawing bounds on screen.
color
ColorA 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
StaticSpriteBatchtexture
Texture2DA texture.
destinationRectangle
RectangleFThe drawing bounds on screen.
sourceRectangle
Rectangle?An optional region on the texture which will be rendered. If null - draws full texture.
color
ColorA 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
StaticSpriteBatchtexture
Texture2DA texture.
destinationRectangle
RectangleFThe drawing bounds on screen.
sourceRectangle
Rectangle?An optional region on the texture which will be rendered. If null - draws full texture.
color
ColorA color mask.
rotation
floatA rotation of this sprite.
origin
Vector2Center of the rotation. 0,0 by default.
effects
SpriteEffectsModificators for drawing. Can be combined.
layerDepth
floatA 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
SpriteBatchThe sprite batch to draw with.
texture
Texture2DA texture.
destinationRectangle
RectangleFThe drawing bounds on screen.
color
ColorA 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
SpriteBatchThe sprite batch to draw with.
texture
Texture2DA texture.
destinationRectangle
RectangleFThe drawing bounds on screen.
sourceRectangle
Rectangle?An optional region on the texture which will be rendered. If null - draws full texture.
color
ColorA 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
SpriteBatchThe sprite batch to draw with.
texture
Texture2DA texture.
destinationRectangle
RectangleFThe drawing bounds on screen.
sourceRectangle
Rectangle?An optional region on the texture which will be rendered. If null - draws full texture.
color
ColorA color mask.
rotation
floatA rotation of this sprite.
origin
Vector2Center of the rotation. 0,0 by default.
effects
SpriteEffectsModificators for drawing. Can be combined.
layerDepth
floatA 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
SpriteBatchThe sprite batch
color
ColorThe color of the texture
size
intThe 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
SpriteBatchThe sprite batch
topLeft
ColorThe color of the texture's top left corner
topRight
ColorThe color of the texture's top right corner
bottomLeft
ColorThe color of the texture's bottom left corner
bottomRight
ColorThe color of the texture's bottom right corner
width
intThe width of the resulting texture, or 256 by default
height
intThe 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
SpriteBatchThe sprite batch
color
ColorThe 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
SpriteBatchThe sprite batch
color
ColorThe fill color of the texture
outlineColor
Color?The outline color of the texture
Returns
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
SpriteBatchThe sprite batch
Returns
- Texture2D
A 1x1 pixel white texture