Advertisement
truefire

Tilemap Auto-Detect Size

Jun 17th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. Tilemap::Tilemap(sf::Image* _image)
  2. {
  3.     sf::Vector2u size = _image->getSize();
  4.     int w = size.x, int h = size.y;
  5.     int* pixels = (int*)_image->getPixelsPtr();
  6.     int i, j, k;
  7.     int color;
  8.     bool good;
  9.  
  10.     j = 0;
  11.     while (j < h)
  12.     {
  13.         color = pixels[j*w];
  14.         good = true;
  15.         k = j;
  16.         while (k < h)
  17.         {
  18.             while (i < w)
  19.             {
  20.                 if (pixels[i+k*w] != color || pixels[k+i*w] != color) {good = false; break;}
  21.             }
  22.             if (!good) { j++; break; }
  23.             k += j+1;
  24.         }
  25.     }
  26.     if (good) { tileWidth = tileHeight = j; }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement