Skip to content

SpriteSheet

Matthew Daly edited this page Feb 12, 2023 · 9 revisions

Namespace: Verdant

class SpriteSheet

public class SpriteSheet : RenderObject

A SpriteSheet is a RenderObject that stores an entire texture sheet, indexed by X,Y coordinates.

Navigate

Constructors

public SpriteSheet

public SpriteSheet(Texture2D sheetTexture, int spriteWidth)

Initialize a new SpriteSheet, indexed by X coordinates.

Parameter Description
Texture2D sheetTexture The Texture2D sheet of sprites. Sprites should be in one row, ordered left to right.
int spriteWidth The width of each sprite.

public SpriteSheet

public SpriteSheet(Texture2D sheetTexture, int spriteWidth, int spriteHeight)

Initialize a new 2D SpriteSheet, indexed by X and Y coordinates.

Parameter Description
Texture2D sheetTexture The Texture2D sheet of sprites. Sprites should be in a 2D grid of uniform rows and columns.
int spriteWidth The width of each sprite.
int spriteHeight The height of each sprite.

Methods

Sprite GetSprite

public Sprite GetSprite(int x, int y = 0)

Get a Sprite of the full sheet cropped at the given x (and optionally y position).

Returns: A Sprite of the sheet cropped at the given coordinates.

Parameter Description
int x The x position of the sprite.
int y = 0 The y position of the sprite.

void Draw

public override void Draw(SpriteBatch spriteBatch, Rectangle bounds)

Draw the first sprite on the sheet. Use DrawIndex to draw a specific sprite.

Parameter Description
SpriteBatch spriteBatch The SpriteBatch to draw with.
Rectangle bounds The screen-space bounds to draw to.

void Draw

public override void Draw(SpriteBatch spriteBatch, Rectangle bounds, float angle, Vector2 origin)
Parameter Description
SpriteBatch spriteBatch
Rectangle bounds
float angle
Vector2 origin

void DrawIndex

public override void DrawIndex(SpriteBatch spriteBatch, Rectangle bounds, int x, int y = 0)

Draw the sprite at the given index on the sheet.

Parameter Description
SpriteBatch spriteBatch The SpriteBatch to draw with.
Rectangle bounds The screen-space bounds to draw to.
int x The x coordinate of the sprite on the sheet.
int y = 0 The y coordinate of the sprite on the sheet. Some sheets are not indexed with y coordinates.

void DrawIndex

public override void DrawIndex(SpriteBatch spriteBatch, Rectangle bounds, float angle, Vector2 origin, int x, int y = 0)
Parameter Description
SpriteBatch spriteBatch
Rectangle bounds
float angle
Vector2 origin
int x
int y = 0
Clone this wiki locally