Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Wraps a rectangle around every sprite in a sprite sheet and stores it in an array of rectangles(Clip[])
- void spriteSheet(string FileName, int SpriteWidth = 64,int SpriteHeight= 64, int SheetDimension = 4){
- int Sprites = SheetDimension * SheetDimension;// Number of Sprites on sheet
- SDL_Rect Clip[Sprites]; // 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.
- for(int i = 0; i< Sprites; 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++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement