-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSpriteSheet.cs
More file actions
30 lines (23 loc) · 1.08 KB
/
SpriteSheet.cs
File metadata and controls
30 lines (23 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System.Drawing;
namespace FlowTimer {
public class SpriteSheet {
private Bitmap[] SubBitmaps;
public SpriteSheet(Bitmap bitmap, int spriteWidth, int spriteHeight) {
int numSpritesPerColumn = bitmap.Width / spriteWidth;
int numSpritesPerRow = bitmap.Height / spriteHeight;
SubBitmaps = new Bitmap[numSpritesPerColumn * numSpritesPerRow];
for(int x = 0; x < numSpritesPerColumn; x++) {
for(int y = 0; y < numSpritesPerRow; y++) {
int index = x + y * numSpritesPerColumn;
SubBitmaps[index] = new Bitmap(spriteWidth, spriteHeight);
using(Graphics graphics = Graphics.FromImage(SubBitmaps[index])) {
graphics.DrawImage(bitmap, new Rectangle(0, 0, spriteWidth, spriteHeight), x * spriteWidth, y * spriteHeight, spriteWidth, spriteHeight, GraphicsUnit.Pixel);
}
}
}
}
public Bitmap this[int index] {
get { return SubBitmaps[index]; }
}
}
}