Original Post
EDIT:: Okay, I managed to solve the problem regarding tile_src.left getting crazy numbers--turns out that my values for world_cameray were being computed incorrectly, so the value for world_cameray was more than it should possibly be leading to problems......Now my issue is with clipping. How can I stop the tiles from "bleeding" over to the other side of the screen? Do I need to expand my for loop for drawing the tiles to include an extra iteration? That is, if the screen is divided normally into say 20 tiles wide, when there is an offset, I have to draw 19 tiles completely, plus parts of 2. So how should my iteration account for this? One thing I am thinking is iterate from tile 2-20 then manually add tiles 1 and 21. Would that be a good thing to do ? [/edit] Hey, I am having a problem with my rendering...I have traced it down to my draw tiles function and it involves the fact that tile_src.left can equal absolutely crazy numbers..... Here is my function--i put some extra comments in to explain some odd things: I should note that the reason I am all of a sudden running into issues with this is that previously you could only scroll in multiples of the tilesize. Now I would like more smooth scrolling.... Btw, if I get this to work, do you have any suggestions for what to do about some clipping problems with parts of the tile carrying over to the other half of the screen? Thanks for your help! [Edited by - GameDev135 on November 15, 2004 11:37:49 PM]
void draw_tiles(void) {
int tile;
int x, y;
int scroll_x, scroll_y; // (NEW)
int offset_x, offset_y; // (NEW)
RECT tile_src;
POINT point;
int numRows = g_level.GetRows();
int numCols = g_level.GetCols();
short int *temp = g_level.GetMap();
for (y = 0; y < SCREEN_SIZEY && y< numRows; y++) {
for (x = 0; x < SCREEN_SIZEX && y < numCols; x++) {
scroll_x = x + (world_camerax / g_level.GetTileSize().x);
scroll_y = y + (world_cameray / g_level.GetTileSize().y);
offset_x = world_camerax % (g_level.GetTileSize().x );
offset_y = world_cameray % (g_level.GetTileSize().y ); //someone suggested to me that i put the following 2 lines instead, but those don't work either.
// offset_x = world_camerax & g_level.GetTileSize().x;
// offset_y = world_cameray & g_level.GetTileSize().y;
tile = * ( temp + (scroll_y * numCols) + scroll_x);
/* tile is a pointer to a short int. The way I store the map is as a dynamically allocated array of short ints....i realize this makes little sense, but its a long story why I did this, and at this point its too late to change it anyway....but this calculation has always been proper previous to this */
tile_src.left = (tile - 1) * g_level.GetTileSize().x;
tile_src.top = 0;
tile_src.right = g_level.GetTileSize().x;
tile_src.bottom = g_level.GetTileSize().y;
point.x = x * g_level.GetTileSize().x - offset_x;
point.y = y * g_level.GetTileSize().y - offset_y;
CopySurfaceToSurface(&tile_src,g_tiles,&point ,g_pBackSurface,TRUE,D3DCOLOR_ARGB(255,255,0,255)); /* this function is from The Zen Direct 3d Book by Walsh--I have used it many times before and it doesn't cause issues */
}
}
}