Advertisement

help blting tiles

Started by February 27, 2001 11:04 PM
2 comments, last by OoMMMoO 23 years, 11 months ago
I was planning on using this code to blt my tiles But as I look at it, it wont blt partial tiles like when I want to scroll right I want it to show less and less of the left tiles as I scroll more and more right anyone know how to do this? Please help me firsttilex=camerax/TileWidth; firsttiley=cameray/TileWidth; int xcounter=0; int ycounter=0; for(int y=firsttiley;y<MAXYTILES;y++) { for(int x=firsttilex;x<MAXXTILES;x++) { map[y][x].dgraphic.right=xcounter+=TILEWIDTH; map[y][x].dgraphic.left=xcounter; map[y][x].dgraphic.top=ycounter; map[y][x].dgraphic.bottom=ycounter+=TILEWIDTH; BltTile(map[x][y].dgraphic); xcounter++; } ycounter++; } OoMMMoO
Just right a function to clip a destination and source rectangle into a bounding box. Also, using nested loops can be optimized to a single while loop that increments a tile pointer until it is done with the last tile as long as the tiles are stored in a single connected block of memory.

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://www.gdarchive.net/druidgames/
Advertisement
That wasnt much help I know I need to do that but Im not sure how. The code I have will only scroll tile by tile and I want it to scrool pixel by pixel anyone have any help?
Well, have a camera object that stores the current x and y offset from the "center". Then use a function like the following (you could probably use quadtrees also, there was a tuturial on them a little while ago ):
  // dRect = Destination Rectangle// sRect = Source Rectangle://         left = top = 0, right = width, bottom = height// rRect = Screen Rect://         left = top = 0, right = width, bottom = height/* Returns false if the tile is offscreen, true otherwise. Modifies all rectangles as nescessary. I meant this to be used with DDraw, since it was part of my old DDraw engine, before I switched to OpenGL */bool buildMODsRect(RECT &dRect, RECT &sRect, RECT rRect) {  if(dRect.right<rRect.left) {    return false;  } else if(dRect.left<rRect.left) {    sRect.left += rRect.left-dRect.left;    dRect.left = rRect.left;  }  if(dRect.bottom<rRect.top) {    return false;  } else if(dRect.top<rRect.top) {    sRect.top += rRect.top-dRect.top;    dRect.top = rRect.top;  }  if(dRect.left>rRect.right) {    return false;  } else if(dRect.right>rRect.right) {    sRect.right -= dRect.right-rRect.right;    dRect.right = rRect.right;  }  if(dRect.top>rRect.bottom) {    return false;  } else if(dRect.bottom>rRect.bottom) {    sRect.bottom -= dRect.bottom-rRect.bottom;    dRect.bottom = rRect.bottom;  }  return true;}  


"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://www.gdarchive.net/druidgames/

This topic is closed to new replies.

Advertisement