For my videogame in C - SDL I need to use a spritesheet I made myself. The picture size is 100x100 and each picture I want to take is 25x25
我发现,在什么地方可以做些事情:
// Wraps a rectangle around every sprite in a sprite sheet and stores it in an array of rectangles(Clip[])
void spriteSheet(){
int SpriteWidth = 25; int SpriteHeight= 25; int SheetDimension = 4;
int LeSprites = SheetDimension * SheetDimension;// Number of Sprites on sheet
SDL_Rect Clip[LeSprites]; // Rectangles that will wrap around each sprite
int SpriteXNum = 0;// The number sprite going from left to right
int SpriteYNum = 0;// The number sprite going from top to bottom
int YIncrement = 0;// Increment for each row.
int i = 0;
for(i = 0; i< LeSprites; i++){// While i is less than number of sprites
if(i = 0){// First sprite starts at 0,0
Clip[i].x = 0;
Clip[i].y = 0;
Clip[i].w = SpriteWidth;
Clip[i].h = SpriteHeight;
}
else{
if(SpriteXNum < SheetDimension - 1 ){// If we have reached the end of the row, go back to the front of the next row
SpriteXNum = 0;
}
if(YIncrement < SheetDimension - 1){
SpriteYNum += 1; // Example of 4X4 Sheet
} // ________________
Clip[i].x = SpriteWidth * SpriteXNum; // | 0 | 1 | 2 | 3 |
Clip[i].y = SpriteHeight * SpriteYNum; // |===============|
// | 0 | 1 | 2 | 3 |
// |===============|
Clip[i].w = SpriteWidth; // | 0 | 1 | 2 | 3 |
Clip[i].h = SpriteHeight; // |===============|
// | 0 | 1 | 2 | 3 |
} // |---------------|
SpriteXNum++;
YIncrement++;
}
}
但现在我知道,我怎么能够把我的(平方)画上来运用这一职能。