Interface ISpriteBatch
Definition
Namespace: StardewUI.Graphics
Assembly: StardewUI.dll
Abstraction for the SpriteBatch providing sprite-drawing methods.
Implements
IDisposable
Remarks
Importantly, this interface represents a "local" sprite batch with inherited transforms, so that views using it do not need to be given explicit information about global coordinates.
Members
Methods
| Name | Description |
|---|---|
| Blend(BlendState) | Sets up subsequent draw calls to use the designated blending settings. |
| Clip(Rectangle) | Sets up subsequent draw calls to clip contents within the specified bounds. |
| DelegateDraw(Action<SpriteBatch, Vector2>) | Draws using a delegate action on a concrete SpriteBatch. |
| Draw(Texture2D, Vector2, Rectangle?, Color?, Single, Single, SpriteEffects, Single) | |
| Draw(Texture2D, Vector2, Rectangle?, Color?, Single, Vector2?, SpriteEffects, Single) | |
| Draw(Texture2D, Rectangle, Rectangle?, Color?, Single, SpriteEffects, Single) | |
| DrawString(SpriteFont, string, Vector2, Color, Single, Single, SpriteEffects, Single) | |
| InitializeRenderTarget(RenderTarget2D, Int32, Int32) | Initializes a RenderTarget2D for use with SetRenderTarget(RenderTarget2D, Color?). |
| Rotate(Single, TransformOrigin) | Applies a rotation transformation to subsequent operations. |
| SaveTransform() | Saves the current transform, so that it can later be restored to its current state. |
| Scale(Single, TransformOrigin) | Applies a uniform scale transformation to subsequent operations. |
| Scale(Single, Single, TransformOrigin) | Applies a scale transformation to subsequent operations. |
| Scale(Vector2, TransformOrigin) | Applies a scale transformation to subsequent operations. |
| SetRenderTarget(RenderTarget2D, Color?) | Sets up subsequent draw calls to use a custom render target. |
| Transform(Transform, TransformOrigin) | Applies an arbitrary transformation to subsequent operations. |
| Translate(Vector2) | Applies a translation transformation to subsequent operations. |
| Translate(Single, Single) | Applies a translation transformation to subsequent operations. |
Details
Methods
Blend(BlendState)
Sets up subsequent draw calls to use the designated blending settings.
Parameters
blendState BlendState
Blend state determining the color/alpha blend behavior.
Returns
A disposable instance which, when disposed, will revert to the previous blending state.
Clip(Rectangle)
Sets up subsequent draw calls to clip contents within the specified bounds.
Parameters
clipRect Rectangle
The clipping bounds in local coordinates.
Returns
A disposable instance which, when disposed, will revert to the previous clipping state.
DelegateDraw(Action<SpriteBatch, Vector2>)
Draws using a delegate action on a concrete SpriteBatch.
void DelegateDraw(Action<Microsoft.Xna.Framework.Graphics.SpriteBatch, Microsoft.Xna.Framework.Vector2> draw);
Parameters
draw Action<SpriteBatch, Vector2>
A function that accepts an underlying SpriteBatch as well as the transformed (global/screen) position and draws using that position as the origin (top left).
Remarks
Delegation is provided as a fallback for game-specific "utilities" that require a SpriteBatch and are not trivial to reimplement; the method acts as a bridge between the abstract ISpriteBatch and the concrete-dependent logic.
Most view types shouldn't use this; it is only needed for a few niche features like SpriteText.
Draw(Texture2D, Vector2, Rectangle?, Color?, float, float, SpriteEffects, float)
void Draw(Microsoft.Xna.Framework.Graphics.Texture2D texture, Microsoft.Xna.Framework.Vector2 position, Microsoft.Xna.Framework.Rectangle? sourceRectangle, Microsoft.Xna.Framework.Color? color, float rotation, float scale, Microsoft.Xna.Framework.Graphics.SpriteEffects effects, float layerDepth);
Parameters
texture Texture2D
position Vector2
sourceRectangle Nullable<Rectangle>
rotation Single
scale Single
effects SpriteEffects
layerDepth Single
Draw(Texture2D, Vector2, Rectangle?, Color?, float, Vector2?, SpriteEffects, float)
void Draw(Microsoft.Xna.Framework.Graphics.Texture2D texture, Microsoft.Xna.Framework.Vector2 position, Microsoft.Xna.Framework.Rectangle? sourceRectangle, Microsoft.Xna.Framework.Color? color, float rotation, Microsoft.Xna.Framework.Vector2? scale, Microsoft.Xna.Framework.Graphics.SpriteEffects effects, float layerDepth);
Parameters
texture Texture2D
position Vector2
sourceRectangle Nullable<Rectangle>
rotation Single
effects SpriteEffects
layerDepth Single
Draw(Texture2D, Rectangle, Rectangle?, Color?, float, SpriteEffects, float)
void Draw(Microsoft.Xna.Framework.Graphics.Texture2D texture, Microsoft.Xna.Framework.Rectangle destinationRectangle, Microsoft.Xna.Framework.Rectangle? sourceRectangle, Microsoft.Xna.Framework.Color? color, float rotation, Microsoft.Xna.Framework.Graphics.SpriteEffects effects, float layerDepth);
Parameters
texture Texture2D
destinationRectangle Rectangle
sourceRectangle Nullable<Rectangle>
rotation Single
effects SpriteEffects
layerDepth Single
DrawString(SpriteFont, string, Vector2, Color, float, float, SpriteEffects, float)
void DrawString(Microsoft.Xna.Framework.Graphics.SpriteFont spriteFont, string text, Microsoft.Xna.Framework.Vector2 position, Microsoft.Xna.Framework.Color color, float rotation, float scale, Microsoft.Xna.Framework.Graphics.SpriteEffects effects, float layerDepth);
Parameters
spriteFont SpriteFont
text string
position Vector2
color Color
rotation Single
scale Single
effects SpriteEffects
layerDepth Single
InitializeRenderTarget(RenderTarget2D, int, int)
Initializes a RenderTarget2D for use with SetRenderTarget(RenderTarget2D, Color?).
void InitializeRenderTarget(Microsoft.Xna.Framework.Graphics.RenderTarget2D target, int width, int height);
Parameters
target RenderTarget2D
The previous render target, if any, to reuse if possible.
width Int32
The target width.
height Int32
The target height.
Remarks
This will reuse an existing render target if available, i.e. if target is not null and matches the specified width and height; otherwise it will replace any previous target and replace it with a new instance.
Rotate(float, TransformOrigin)
Applies a rotation transformation to subsequent operations.
Parameters
angle Single
The rotation angle, in radians.
origin TransformOrigin
The center of the rotation, or null to use the Default origin.
SaveTransform()
Saves the current transform, so that it can later be restored to its current state.
Returns
A disposable instance which, when disposed, restores the transform of this ISpriteBatch to the same state it was in before SaveTransform was called.
Remarks
This is typically used in hierarchical layout; i.e. a view with children would apply a transform before handing the canvas or sprite batch down to any of those children, and then restore it after the child is done with it. This enables a single ISpriteBatch instance to be used for the entire layout rather than having to create a tree.
Scale(float, TransformOrigin)
Applies a uniform scale transformation to subsequent operations.
Parameters
scale Single
Amount to scale, both horizontally and vertically. 1 is unity scale.
origin TransformOrigin
The center of the scaling, or null to use the Default origin.
Scale(float, float, TransformOrigin)
Applies a scale transformation to subsequent operations.
Parameters
x Single
Amount of horizontal scaling. 1 is unity scale.
y Single
Amount of vertical scaling. 1 is unity scale.
origin TransformOrigin
The center of the scaling, or null to use the Default origin.
Scale(Vector2, TransformOrigin)
Applies a scale transformation to subsequent operations.
Parameters
scale Vector2
Scaling vector containing the horizontal (X) and vertical (Y) scaling amounts.
origin TransformOrigin
The center of the scaling, or null to use the Default origin.
SetRenderTarget(RenderTarget2D, Color?)
Sets up subsequent draw calls to use a custom render target.
System.IDisposable SetRenderTarget(Microsoft.Xna.Framework.Graphics.RenderTarget2D renderTarget, Microsoft.Xna.Framework.Color? clearColor);
Parameters
renderTarget RenderTarget2D
The new render target.
clearColor Nullable<Color>
Color to clear the renderTarget with after making it active, or null to skip clearing.
Returns
A disposable instance which, when disposed, will revert to the previous render target(s).
Remarks
This will also reset any active transforms for the new render target, e.g. those resulting from Translate(Vector2). Previously-active transforms will be restored when the render target is reverted by calling Dispose() on the result.
Transform(Transform, TransformOrigin)
Applies an arbitrary transformation to subsequent operations.
Parameters
transform Transform
The transform properties (scale, rotation and translation).
origin TransformOrigin
The origin (i.e. center) of the transformation, or null to use the Default origin.
Translate(Vector2)
Applies a translation transformation to subsequent operations.
Parameters
translation Vector2
The translation vector.
Translate(float, float)
Applies a translation transformation to subsequent operations.
Parameters
x Single
The translation's X component.
y Single
The translation's Y component.