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
batchStaticSpriteBatchtextureTexture2DA texture.
destinationRectangleRectangleFThe drawing bounds on screen.
colorColorA 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
batchStaticSpriteBatchtextureTexture2DA texture.
destinationRectangleRectangleFThe drawing bounds on screen.
sourceRectangleRectangle?An optional region on the texture which will be rendered. If null - draws full texture.
colorColorA 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
batchStaticSpriteBatchtextureTexture2DA texture.
destinationRectangleRectangleFThe drawing bounds on screen.
sourceRectangleRectangle?An optional region on the texture which will be rendered. If null - draws full texture.
colorColorA color mask.
rotationfloatA rotation of this sprite.
originVector2Center of the rotation. 0,0 by default.
effectsSpriteEffectsModificators for drawing. Can be combined.
layerDepthfloatA 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
batchSpriteBatchThe sprite batch to draw with.
textureTexture2DA texture.
destinationRectangleRectangleFThe drawing bounds on screen.
colorColorA 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
batchSpriteBatchThe sprite batch to draw with.
textureTexture2DA texture.
destinationRectangleRectangleFThe drawing bounds on screen.
sourceRectangleRectangle?An optional region on the texture which will be rendered. If null - draws full texture.
colorColorA 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
batchSpriteBatchThe sprite batch to draw with.
textureTexture2DA texture.
destinationRectangleRectangleFThe drawing bounds on screen.
sourceRectangleRectangle?An optional region on the texture which will be rendered. If null - draws full texture.
colorColorA color mask.
rotationfloatA rotation of this sprite.
originVector2Center of the rotation. 0,0 by default.
effectsSpriteEffectsModificators for drawing. Can be combined.
layerDepthfloatA 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
batchSpriteBatchThe sprite batch
colorColorThe color of the texture
sizeintThe 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
batchSpriteBatchThe sprite batch
topLeftColorThe color of the texture's top left corner
topRightColorThe color of the texture's top right corner
bottomLeftColorThe color of the texture's bottom left corner
bottomRightColorThe color of the texture's bottom right corner
widthintThe width of the resulting texture, or 256 by default
heightintThe height of the resulting texture, or 256 by default
Returns
- Texture2D
A new texture with the given data
GenerateNinePatch(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 GenerateNinePatch(this SpriteBatch batch, Color color, Color outlineColor)
Parameters
batchSpriteBatchThe sprite batch
colorColorThe fill color of the texture
outlineColorColorThe outline color of the texture
Returns
GenerateSquareTexture(SpriteBatch, Color)
Generates a 1x1 texture with the given color. This texture is automatically disposed of when the batch is disposed.
[Obsolete("Use the new GenerateTexture instead")]
public static Texture2D GenerateSquareTexture(this SpriteBatch batch, Color color)
Parameters
batchSpriteBatchThe sprite batch
colorColorThe color of the texture
Returns
- Texture2D
A new texture with the given data
GenerateTexture(SpriteBatch, Color, int, int)
Generates a texture with the given width and height, which will be filled with the given color.
This texture is automatically disposed of when the batch is disposed.
public static Texture2D GenerateTexture(this SpriteBatch batch, Color color, int width, int height)
Parameters
batchSpriteBatchThe sprite batch
colorColorThe color of the texture
widthintThe width of the resulting texture
heightintThe height of the resulting 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.
[Obsolete("Use the new GenerateNinePatch instead")]
public static NinePatch GenerateTexture(this SpriteBatch batch, Color color, Color? outlineColor = null)
Parameters
batchSpriteBatchThe sprite batch
colorColorThe fill color of the texture
outlineColorColor?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
batchSpriteBatchThe sprite batch
Returns
- Texture2D
A 1x1 pixel white texture