Advertisement
Kitomas

tile.cpp as of 2024-04-12

Apr 12th, 2024
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <tile.hpp>
  2.  
  3. using namespace kit;
  4.  
  5.  
  6.  
  7. void Scene::drawBg(){
  8.   if(bmp_bg == nullptr) return;
  9.   shape::point sizeBmp = bmp_bg->getSize();
  10.   if(sizeBmp.x<1 || sizeBmp.y<1) return;
  11.  
  12.  
  13.   if(stretch_bg){ //stretch entire background to entire canvas
  14.     bmp_bg->blitRect();
  15.  
  16.  
  17.   } else { //otherwise, repeat background bitmap in a tile pattern
  18.     shape::rect dst; //destination rectangle
  19.     dst.w = sizeBmp.x;
  20.     dst.h = sizeBmp.y;
  21.  
  22.     shape::point sizeCanvas = gl_win->getCanvasSize();
  23.  
  24.     //increase x, then y until the entire canvas is drawn to
  25.     for(dst.y = 0;  dst.y < sizeCanvas.y;  dst.y += dst.h)
  26.     for(dst.x = 0;  dst.x < sizeCanvas.x;  dst.x += dst.w)
  27.     {
  28.       bmp_bg->blitRect(&dst, nullptr); //whole bitmap is used when src = nullptr
  29.     }
  30.  
  31.  
  32.   }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement