I've got a really weird problem which I've been working on for a couple of hours and I still can't figure out what's going on.
Basically, I have a structure used to store information about tiles when they are placed on the map:
struct SAVED_BG_TILES {
int xpos; // top left x coordinate
int ypos; // top left y coordinate
void * bmp; // will eventually point to an HBITMAP stored in a vector
};
SAVED_BG_TILES *saved_bg_tiles;
When a tile is put on the map (more precisely, when WM_LBUTTONDOWN gets called for the main window), I'm doing this (assume saved_bg_tiles has been allocated to hold the number of tiles on the map):
saved_bg_tiles[(TILE_WIDTH*correctX)+correctY].bmp = currentlySelectedTile;
correctX and correctY are found like this:
int correctX = hwndMouseX / TILE_WIDTH;
int correctY = hwndMouseY / TILE_HEIGHT;
Now, when the map needs to be repainted this is the code I'm using to redraw all of the tiles onto the map:
for(int i = 0; i < TILES_WIDE*TILES_HIGH; i++)
{
hdc = GetDC(hwnd);
HDC image_hdc = CreateCompatibleDC(hdc);
SelectObject(image_hdc,saved_bg_tiles.bmp);
BitBlt(hdc,saved_bg_tiles.xpos,saved_bg_tiles.ypos,TILE_WIDTH,TILE_HEIGHT,image_hdc,0,0,SRCCOPY);
ReleaseDC(hwnd,hdc);
DeleteDC(image_hdc);
}
I thought that this would draw all of the bitmaps on the correct spots on the map, but it doesn't. Well it does and this is why it's weird. It only redraws a selection of the tiles on the map. Here's a couple of screenshots to show what I mean:
Before the screen needs to be redrawn:
after it gets redrawn:
I cannot figure out why it would be doing this! Any ideas?