Advertisement
Guest User

Untitled

a guest
Jun 28th, 2010
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. // Wraps a rectangle around every sprite in a sprite sheet and stores it in an array of rectangles(Clip[])
  2.  
  3. void spriteSheet(string FileName, int SpriteWidth = 64,int SpriteHeight= 64, int SheetDimension = 4){
  4.  
  5.  
  6.     int Sprites = SheetDimension * SheetDimension;// Number of Sprites on sheet
  7.     SDL_Rect Clip[Sprites]; // Rectangles that will wrap around each sprite
  8.  
  9.     int SpriteXNum = 0;// The number sprite going from left to right
  10.     int SpriteYNum = 0;// The number sprite going from top to bottom
  11.     int YIncrement = 0;// Increment for each row.
  12.     for(int i = 0; i< Sprites; i++){// While i is less than number of sprites
  13.  
  14.         if(i = 0){// First sprite starts at 0,0
  15.             Clip[i].x = 0;
  16.             Clip[i].y = 0;
  17.             Clip[i].w = SpriteWidth;
  18.             Clip[i].h = SpriteHeight;
  19.         }
  20.         else{
  21.  
  22.             if(SpriteXNum < SheetDimension - 1 ){// If we have reached the end of the row, go back to the front of the next row
  23.                 SpriteXNum = 0;
  24.             }
  25.             if(YIncrement < SheetDimension - 1){
  26.                 SpriteYNum += 1;                         // Example of 4X4 Sheet
  27.             }                                            //   ________________
  28.             Clip[i].x = SpriteWidth * SpriteXNum;        //  | 0 | 1 | 2 | 3 |
  29.             Clip[i].y = SpriteHeight * SpriteYNum;       //  |===============|
  30.                                                          //  | 0 | 1 | 2 | 3 |
  31.                                                          //  |===============|
  32.             Clip[i].w = SpriteWidth;                     //  | 0 | 1 | 2 | 3 |
  33.             Clip[i].h = SpriteHeight;                    //  |===============|
  34.                                                          //  | 0 | 1 | 2 | 3 |
  35.         }                                                //  |---------------|
  36.         SpriteXNum++;
  37.         YIncrement++;
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement