SpriteSheet
Struct · namespace System.Graphics · Since 0.45
struct SpriteSheetAn 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 secondsheet.Draw(ref canvas, frame, x, y, lookingLeft ? Flip.Horizontal : Flip.None);Fields
Section titled “Fields”| 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 ImageThe image with all frames.
FrameWidth
Section titled “FrameWidth”int FrameWidthThe width of a frame.
FrameHeight
Section titled “FrameHeight”int FrameHeightThe height of a frame.
Spacing
Section titled “Spacing”int SpacingPixels between two frames and around them.
Static methods
Section titled “Static methods”| Name | Description |
|---|---|
Create |
A sheet of frames of frameWidth x frameHeight pixels without spacing. |
Create
Section titled “Create”static SpriteSheet Create(Image image, int frameWidth, int frameHeight)A sheet of frames of frameWidth x frameHeight pixels without spacing.
Methods
Section titled “Methods”| 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). |
Columns
Section titled “Columns”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.