Skip to content
CShift0.45

SpriteSheet

Struct · namespace System.Graphics · Since 0.45

struct SpriteSheet

An image cut into frames of the same size, from left to right and top to bottom: the tiles of a map, the frames of an animation.

var sheet = SpriteSheet.Create(try Image.Load("hero.png"), 16, 16);
int frame = (int)(time * 8.0) % 4; // 8 frames a second
sheet.Draw(ref canvas, frame, x, y, lookingLeft ? Flip.Horizontal : Flip.None);
Name Description
Image The image with all frames.
FrameWidth The width of a frame.
FrameHeight The height of a frame.
Spacing Pixels between two frames and around them.
Image Image

The image with all frames.

int FrameWidth

The width of a frame.

int FrameHeight

The height of a frame.

int Spacing

Pixels between two frames and around them.

Name Description
Create A sheet of frames of frameWidth x frameHeight pixels without spacing.
static SpriteSheet Create(Image image, int frameWidth, int frameHeight)

A sheet of frames of frameWidth x frameHeight pixels without spacing.

Name Description
Columns The number of frames in a row.
Rows The number of rows of frames.
Count The number of frames.
Frame The rectangle of frame index (counted row by row) in SpriteSheet.Image.
Draw Draws frame index with its top left corner at (x, y).
int Columns()

The number of frames in a row.

int Rows()

The number of rows of frames.

int Count()

The number of frames.

Rect Frame(int index)

The rectangle of frame index (counted row by row) in SpriteSheet.Image.

Rect Frame(int column, int row)

The rectangle of the frame in column and row.

void Draw(ref Canvas canvas, int index, int x, int y)

Draws frame index with its top left corner at (x, y).

void Draw(ref Canvas canvas, int index, int x, int y, Flip flip)

Draws frame index at (x, y), mirrored by flip.