SpriteBatch¶
-
class
SpriteBatch
: GraphicsResource, System.IDisposable Helper class for drawing text strings and sprites in one or more optimized batches.
-
public void
Begin
(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, System.Nullable<Matrix> transformMatrix) Begins a new sprite and text batch with the specified render state.
Parameters: - sortMode (Microsoft.Xna.Framework.Graphics.SpriteSortMode) – The drawing order for sprite and text drawing. F:Microsoft.Xna.Framework.Graphics.SpriteSortMode.Deferred by default.
- blendState (Microsoft.Xna.Framework.Graphics.BlendState) – State of the blending. Uses F:Microsoft.Xna.Framework.Graphics.BlendState.AlphaBlend if null.
- samplerState (Microsoft.Xna.Framework.Graphics.SamplerState) – State of the sampler. Uses F:Microsoft.Xna.Framework.Graphics.SamplerState.LinearClamp if null.
- depthStencilState (Microsoft.Xna.Framework.Graphics.DepthStencilState) – State of the depth-stencil buffer. Uses F:Microsoft.Xna.Framework.Graphics.DepthStencilState.None if null.
- rasterizerState (Microsoft.Xna.Framework.Graphics.RasterizerState) – State of the rasterization. Uses F:Microsoft.Xna.Framework.Graphics.RasterizerState.CullCounterClockwise if null.
- effect (Microsoft.Xna.Framework.Graphics.Effect) – A custom T:Microsoft.Xna.Framework.Graphics.Effect to override the default sprite effect. Uses default sprite effect if null.
- transformMatrix (System.Nullable<Matrix>) – An optional matrix used to transform the sprite geometry. Uses P:Microsoft.Xna.Framework.Matrix.Identity if null.
-
public void
End
() Flushes all batched text and sprites to the screen.
-
public void
Draw
(Texture2D texture, System.Nullable<Vector2> position, System.Nullable<Rectangle> destinationRectangle, System.Nullable<Rectangle> sourceRectangle, System.Nullable<Vector2> origin, float rotation, System.Nullable<Vector2> scale, System.Nullable<Color> color, SpriteEffects effects, float layerDepth) Submit a sprite for drawing in the current batch.
Parameters: - texture (Microsoft.Xna.Framework.Graphics.Texture2D) – A texture.
- position (System.Nullable<Vector2>) – The drawing location on screen or null if is used.
- destinationRectangle (System.Nullable<Rectangle>) – The drawing bounds on screen or null if is used.
- sourceRectangle (System.Nullable<Rectangle>) – An optional region on the texture which will be rendered. If null - draws full texture.
- origin (System.Nullable<Vector2>) – An optional center of rotation. Uses P:Microsoft.Xna.Framework.Vector2.Zero if null.
- rotation (float) – An optional rotation of this sprite. 0 by default.
- scale (System.Nullable<Vector2>) – An optional scale vector. Uses P:Microsoft.Xna.Framework.Vector2.One if null.
- color (System.Nullable<Color>) – An optional color mask. Uses P:Microsoft.Xna.Framework.Color.White if null.
- effects (Microsoft.Xna.Framework.Graphics.SpriteEffects) – The optional drawing modificators. F:Microsoft.Xna.Framework.Graphics.SpriteEffects.None by default.
- layerDepth (float) – An optional depth of the layer of this sprite. 0 by default.
-
public void
Draw
(Texture2D texture, Vector2 position, System.Nullable<Rectangle> sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) Submit a sprite for drawing in the current batch.
Parameters: - texture (Microsoft.Xna.Framework.Graphics.Texture2D) – A texture.
- position (Microsoft.Xna.Framework.Vector2) – The drawing location on screen.
- sourceRectangle (System.Nullable<Rectangle>) – An optional region on the texture which will be rendered. If null - draws full texture.
- color (Microsoft.Xna.Framework.Color) – A color mask.
- rotation (float) – A rotation of this sprite.
- origin (Microsoft.Xna.Framework.Vector2) – Center of the rotation. 0,0 by default.
- scale (Microsoft.Xna.Framework.Vector2) – A scaling of this sprite.
- effects (Microsoft.Xna.Framework.Graphics.SpriteEffects) – Modificators for drawing. Can be combined.
- layerDepth (float) – A depth of the layer of this sprite.
-
public void
Draw
(Texture2D texture, Vector2 position, System.Nullable<Rectangle> sourceRectangle, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) Submit a sprite for drawing in the current batch.
Parameters: - texture (Microsoft.Xna.Framework.Graphics.Texture2D) – A texture.
- position (Microsoft.Xna.Framework.Vector2) – The drawing location on screen.
- sourceRectangle (System.Nullable<Rectangle>) – An optional region on the texture which will be rendered. If null - draws full texture.
- color (Microsoft.Xna.Framework.Color) – A color mask.
- rotation (float) – A rotation of this sprite.
- origin (Microsoft.Xna.Framework.Vector2) – Center of the rotation. 0,0 by default.
- scale (float) – A scaling of this sprite.
- effects (Microsoft.Xna.Framework.Graphics.SpriteEffects) – Modificators for drawing. Can be combined.
- layerDepth (float) – A depth of the layer of this sprite.
-
public void
Draw
(Texture2D texture, Rectangle destinationRectangle, System.Nullable<Rectangle> sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth) Submit a sprite for drawing in the current batch.
Parameters: - texture (Microsoft.Xna.Framework.Graphics.Texture2D) – A texture.
- destinationRectangle (Microsoft.Xna.Framework.Rectangle) – The drawing bounds on screen.
- sourceRectangle (System.Nullable<Rectangle>) – An optional region on the texture which will be rendered. If null - draws full texture.
- color (Microsoft.Xna.Framework.Color) – A color mask.
- rotation (float) – A rotation of this sprite.
- origin (Microsoft.Xna.Framework.Vector2) – Center of the rotation. 0,0 by default.
- effects (Microsoft.Xna.Framework.Graphics.SpriteEffects) – Modificators for drawing. Can be combined.
- layerDepth (float) – A depth of the layer of this sprite.
-
void
FlushIfNeeded
()
-
public void
Draw
(Texture2D texture, Vector2 position, System.Nullable<Rectangle> sourceRectangle, Color color) Submit a sprite for drawing in the current batch.
Parameters: - texture (Microsoft.Xna.Framework.Graphics.Texture2D) – A texture.
- position (Microsoft.Xna.Framework.Vector2) – The drawing location on screen.
- sourceRectangle (System.Nullable<Rectangle>) – An optional region on the texture which will be rendered. If null - draws full texture.
- color (Microsoft.Xna.Framework.Color) – A color mask.
-
public void
Draw
(Texture2D texture, Rectangle destinationRectangle, System.Nullable<Rectangle> sourceRectangle, Color color) Submit a sprite for drawing in the current batch.
Parameters: - texture (Microsoft.Xna.Framework.Graphics.Texture2D) – A texture.
- destinationRectangle (Microsoft.Xna.Framework.Rectangle) – The drawing bounds on screen.
- sourceRectangle (System.Nullable<Rectangle>) – An optional region on the texture which will be rendered. If null - draws full texture.
- color (Microsoft.Xna.Framework.Color) – A color mask.
-
public void
Draw
(Texture2D texture, Vector2 position, Color color) Submit a sprite for drawing in the current batch.
Parameters: - texture (Microsoft.Xna.Framework.Graphics.Texture2D) – A texture.
- position (Microsoft.Xna.Framework.Vector2) – The drawing location on screen.
- color (Microsoft.Xna.Framework.Color) – A color mask.
-
public void
Draw
(Texture2D texture, Rectangle destinationRectangle, Color color) Submit a sprite for drawing in the current batch.
Parameters: - texture (Microsoft.Xna.Framework.Graphics.Texture2D) – A texture.
- destinationRectangle (Microsoft.Xna.Framework.Rectangle) – The drawing bounds on screen.
- color (Microsoft.Xna.Framework.Color) – A color mask.
-
public void
DrawString
(SpriteFont spriteFont, string text, Vector2 position, Color color) Submit a text string of sprites for drawing in the current batch.
Parameters: - spriteFont (Microsoft.Xna.Framework.Graphics.SpriteFont) – A font.
- text (string) – The text which will be drawn.
- position (Microsoft.Xna.Framework.Vector2) – The drawing location on screen.
- color (Microsoft.Xna.Framework.Color) – A color mask.
-
public void
DrawString
(SpriteFont spriteFont, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) Submit a text string of sprites for drawing in the current batch.
Parameters: - spriteFont (Microsoft.Xna.Framework.Graphics.SpriteFont) – A font.
- text (string) – The text which will be drawn.
- position (Microsoft.Xna.Framework.Vector2) – The drawing location on screen.
- color (Microsoft.Xna.Framework.Color) – A color mask.
- rotation (float) – A rotation of this string.
- origin (Microsoft.Xna.Framework.Vector2) – Center of the rotation. 0,0 by default.
- scale (float) – A scaling of this string.
- effects (Microsoft.Xna.Framework.Graphics.SpriteEffects) – Modificators for drawing. Can be combined.
- layerDepth (float) – A depth of the layer of this string.
-
public void
DrawString
(SpriteFont spriteFont, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) Submit a text string of sprites for drawing in the current batch.
Parameters: - spriteFont (Microsoft.Xna.Framework.Graphics.SpriteFont) – A font.
- text (string) – The text which will be drawn.
- position (Microsoft.Xna.Framework.Vector2) – The drawing location on screen.
- color (Microsoft.Xna.Framework.Color) – A color mask.
- rotation (float) – A rotation of this string.
- origin (Microsoft.Xna.Framework.Vector2) – Center of the rotation. 0,0 by default.
- scale (Microsoft.Xna.Framework.Vector2) – A scaling of this string.
- effects (Microsoft.Xna.Framework.Graphics.SpriteEffects) – Modificators for drawing. Can be combined.
- layerDepth (float) – A depth of the layer of this string.
-
public void
DrawString
(SpriteFont spriteFont, System.Text.StringBuilder text, Vector2 position, Color color) Submit a text string of sprites for drawing in the current batch.
Parameters: - spriteFont (Microsoft.Xna.Framework.Graphics.SpriteFont) – A font.
- text (System.Text.StringBuilder) – The text which will be drawn.
- position (Microsoft.Xna.Framework.Vector2) – The drawing location on screen.
- color (Microsoft.Xna.Framework.Color) – A color mask.
-
public void
DrawString
(SpriteFont spriteFont, System.Text.StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) Submit a text string of sprites for drawing in the current batch.
Parameters: - spriteFont (Microsoft.Xna.Framework.Graphics.SpriteFont) – A font.
- text (System.Text.StringBuilder) – The text which will be drawn.
- position (Microsoft.Xna.Framework.Vector2) – The drawing location on screen.
- color (Microsoft.Xna.Framework.Color) – A color mask.
- rotation (float) – A rotation of this string.
- origin (Microsoft.Xna.Framework.Vector2) – Center of the rotation. 0,0 by default.
- scale (float) – A scaling of this string.
- effects (Microsoft.Xna.Framework.Graphics.SpriteEffects) – Modificators for drawing. Can be combined.
- layerDepth (float) – A depth of the layer of this string.
-
public void
DrawString
(SpriteFont spriteFont, System.Text.StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) Submit a text string of sprites for drawing in the current batch.
Parameters: - spriteFont (Microsoft.Xna.Framework.Graphics.SpriteFont) – A font.
- text (System.Text.StringBuilder) – The text which will be drawn.
- position (Microsoft.Xna.Framework.Vector2) – The drawing location on screen.
- color (Microsoft.Xna.Framework.Color) – A color mask.
- rotation (float) – A rotation of this string.
- origin (Microsoft.Xna.Framework.Vector2) – Center of the rotation. 0,0 by default.
- scale (Microsoft.Xna.Framework.Vector2) – A scaling of this string.
- effects (Microsoft.Xna.Framework.Graphics.SpriteEffects) – Modificators for drawing. Can be combined.
- layerDepth (float) – A depth of the layer of this string.
-
public void