SpriteLayer
Declaration
public class Strawberry.Graphics.Layers.SpriteLayer
A layer responsible for batching and rendering sprites within a scene.
Inherits: Strawberry.Graphics.Layers.Layer
Constructors
SpriteLayer
void SpriteLayer()
Properties
ActiveShader
Gets the currently active shader used for sprite rendering.
BasicShader ActiveShader { get }
GraphicsContext
Gets the graphics context for the current scene.
IGraphicsContext GraphicsContext { get }
DrawCalls
Gets or sets the number of draw calls performed during the most recent render pass.
int DrawCalls { get set }
Methods
Initialize override
Initializes the sprite layer and allocates rendering resources.
void Initialize(Scene scene)
Parameters:
| Name | Type | Description |
|---|---|---|
scene |
Strawberry.Core.Scene |
The scene that owns the layer. |
SetShader
Sets the active shader used when rendering sprites.
void SetShader(BasicShader shader)
Parameters:
| Name | Type | Description |
|---|---|---|
shader |
Strawberry.Graphics.BasicShader |
The shader to activate. |
SetBlendMode
Sets the blend mode name used for subsequent sprite draws.
void SetBlendMode(string name)
Parameters:
| Name | Type | Description |
|---|---|---|
name |
System.String |
The blend mode identifier. |
ResetShader
Resets the active shader to the default sprite shader.
void ResetShader()
GetQuad
Creates a sprite quad for the given sprite and transform parameters.
SpriteQuad GetQuad(Sprite sprite, Vector2 position, Vector2 origin, Vector2 scale, Color color, int imageIndex, float angle)
Parameters:
| Name | Type | Description |
|---|---|---|
sprite |
Strawberry.Graphics.Sprite |
The sprite to render. |
position |
Strawberry.Math.Vector2 |
The screen position of the sprite. |
origin |
Strawberry.Math.Vector2 |
The origin used for rotation and scaling. |
scale |
Strawberry.Math.Vector2 |
The scaling factor for the sprite. |
color |
Strawberry.Graphics.Color |
The color tint to apply. |
imageIndex |
System.Int32 |
The frame index within the sprite texture. |
angle |
System.Single |
The rotation angle in degrees. |
Returns: A configured sprite quad ready for batching.
Push
Adds a transformed sprite quad to the current batch.
void Push(Sprite sprite, Vector2 position, Vector2 origin, Vector2 scale, Color color, int imageIndex, float angle)
Parameters:
| Name | Type | Description |
|---|---|---|
sprite |
Strawberry.Graphics.Sprite |
The sprite to draw. |
position |
Strawberry.Math.Vector2 |
The position in scene coordinates. |
origin |
Strawberry.Math.Vector2 |
The origin offset for rotation and scaling. |
scale |
Strawberry.Math.Vector2 |
The scale for the sprite. |
color |
Strawberry.Graphics.Color |
The tint color. |
imageIndex |
System.Int32 |
The frame index in the sprite sheet. |
angle |
System.Single |
The rotation angle in degrees. |
Push
Adds a textured quad to the current batch.
void Push(Texture texture, Vector2 position, Vector2 texSize, Vector2 size, Vector2 topLeft, Color color)
Parameters:
| Name | Type | Description |
|---|---|---|
texture |
Strawberry.Graphics.Texture |
The texture to draw. |
position |
Strawberry.Math.Vector2 |
The position in scene coordinates. |
texSize |
Strawberry.Math.Vector2 |
The size of the source region in texture space. |
size |
Strawberry.Math.Vector2 |
The destination size in scene coordinates. |
topLeft |
Strawberry.Math.Vector2 |
The texture coordinates of the top-left corner. |
color |
Strawberry.Graphics.Color |
The tint color. |
Render override
Renders all batched sprite quads for the current frame.
void Render()
DrawOutlineRectangle
Draws the outline of a rotated rectangle using pixel sprites.
void DrawOutlineRectangle(RotatedRectangle rect, Color color)
Parameters:
| Name | Type | Description |
|---|---|---|
rect |
Strawberry.Common.RotatedRectangle |
The rotated rectangle to outline. |
color |
Strawberry.Graphics.Color |
The color of the outline. |
DrawRectangle
Draws a filled rotated rectangle using a pixel sprite.
void DrawRectangle(RotatedRectangle rect, Color color)
Parameters:
| Name | Type | Description |
|---|---|---|
rect |
Strawberry.Common.RotatedRectangle |
The rectangle to draw. |
color |
Strawberry.Graphics.Color |
The fill color. |
DrawHorizontalLine
Draws a horizontal line using a pixel sprite.
void DrawHorizontalLine(Vector2 start, float length, Color color)
Parameters:
| Name | Type | Description |
|---|---|---|
start |
Strawberry.Math.Vector2 |
The starting position. |
length |
System.Single |
The length of the line. |
color |
Strawberry.Graphics.Color |
The line color. |
DrawVerticalLine
Draws a vertical line using a pixel sprite.
void DrawVerticalLine(Vector2 start, float length, Color color)
Parameters:
| Name | Type | Description |
|---|---|---|
start |
Strawberry.Math.Vector2 |
The starting position. |
length |
System.Single |
The length of the line. |
color |
Strawberry.Graphics.Color |
The line color. |
PushString
Pushes a line of text into the sprite batch using the font's native size.
Vector2 PushString(string text, Font font, Vector2 position, Color color, TextDirection direction)
Parameters:
| Name | Type | Description |
|---|---|---|
text |
System.String |
The text to render. |
font |
Strawberry.Graphics.Text.Font |
The font to use. |
position |
Strawberry.Math.Vector2 |
The starting position in scene coordinates. |
color |
Strawberry.Graphics.Color |
The text color. |
direction |
Strawberry.Graphics.Text.TextDirection |
The text direction. |
Returns: The final draw position after rendering the text.
PushString
Pushes a line of text into the sprite batch at a custom size.
Vector2 PushString(string text, Font font, Vector2 position, Color color, TextDirection direction, float size)
Parameters:
| Name | Type | Description |
|---|---|---|
text |
System.String |
The text to render. |
font |
Strawberry.Graphics.Text.Font |
The font to use. |
position |
Strawberry.Math.Vector2 |
The starting position in scene coordinates. |
color |
Strawberry.Graphics.Color |
The text color. |
direction |
Strawberry.Graphics.Text.TextDirection |
The text direction. |
size |
System.Single |
The target size of the text. |
Returns: The final draw position after rendering the text.