a pontential long run drawing problem
i was working on my map drawing function when i realized that the way i have it set up is very bad and i need some help in reworking it to a more efficient way.
right now i have it set up like this
if map[x][y]==0
drawbitmap 0,0,lppds,cx*32,cy*32
now i realized that if i have a 100 bitmaps to draw i will have to make those 2 calls 100 times and thats a waste of space and time.
now i figured out how to fix part of it but i dont know how to fix the other part
my loop is like this
for x=0;x<20;x++
for y=0;y<14;y++
if map[x][y]==0
drawbitmap 0,0,lpdds,cx*32,cy*32
now if i insert a counter loop like to check the tiles like this
for x=0;x<20;x++
for y=0;y<14;y++
for cnt=0;cnt<100;cnt++
if map[x][y]==cnt
i dont know how to make it so that it draws the right bitmap
i have my bitmap function so that it takes the bitmap off of the surface that the image is loaded on set up like this 0,0 equals the top left corner and 0,1 equals the next bitmap over and each bitmap is 32x32
does this make any sense
quote: Original post by omegasyphon
i was working on my map drawing function when i realized that the way i have it set up is very bad and i need some help in reworking it to a more efficient way.
right now i have it set up like this
if map[x][y]==0
drawbitmap 0,0,lppds,cx*32,cy*32
now i realized that if i have a 100 bitmaps to draw i will have to make those 2 calls 100 times and thats a waste of space and time.
now i figured out how to fix part of it but i dont know how to fix the other part
my loop is like this
for x=0;x<20;x++
for y=0;y<14;y++
if map[x][y]==0
drawbitmap 0,0,lpdds,cx*32,cy*32
now if i insert a counter loop like to check the tiles like this
for x=0;x<20;x++
for y=0;y<14;y++
for cnt=0;cnt<100;cnt++
if map[x][y]==cnt
i dont know how to make it so that it draws the right bitmap
i have my bitmap function so that it takes the bitmap off of the surface that the image is loaded on set up like this 0,0 equals the top left corner and 0,1 equals the next bitmap over and each bitmap is 32x32
does this make any sense
im not sure as to exactly what drawbitmap 0,0, lpdds,cx*32,cy*32 means your might wneed to explain it a bit better. If the 0,0 is a frame number, your need to first decide what frame your looking to get then use your routine.
int frame_x = map[x][y] % number_of_tiles_in_each_row; int frame_y = map[x][y] / number_of_tiles_in_each_row; drawbitmap frame_x,frame_y,lpdds,cx*32,cy*32 [/source]if you need to get your draw bitmap code working better try eithera. load each bitmap / tile onto a seperate surface and store them all in an array of tile surfaces. call it something like background_tile[30] which contains an array to 30 surface pointers then when you are render simply say[source] // Fill the rects up outside render loop to save time // fill in the destination rect // i *think your have cx and cy equal location to start dest_rect.left = location_to_startX; dest_rect.top = location_to_startY; dest_rect.right = location_to_startX +tile_width; dest_rect.bottom = location_to_startX + tile_height; // fill in the source rect source_rect.left = 0; source_rect.top = 0; source_rect.right = tile_width; source_rect.bottom = tile_height; // inside the render loop blit the appropriate surface // assumes map[x][y] corresponds to the right number tile // in the array of background_tile s lpdds->Blt(&dest_rect, &back_groundtile[map[x][y]], &source_rect,(DDBLT_WAIT | DDBLT_KEYSRC), NULL); [/source]or b. *what I think your doing* if your code still isnt working and you have it so that all your tiles are stored on one surface your need to set the source_rect correctly inside the rendering loop[source] // dest rect remains the same dest_rect.left = location_to_startX; dest_rect.top = location_to_startY; dest_rect.right = location_to_startX +tile_width; dest_rect.bottom = location_to_startX + tile_height; // source rectangle must change int frame_x = map[x][y] % number_of_tiles_in_each_row; int frame_y = map[x][y] / number_of_tiles_in_each_row; source_rect.left = tile_width * frame_x; source_rect.top = tile_height * frame_y; source_rect.reight = tile_width *frame_x + tilewidth; source_rect. bottome = tile_width * frame_x + tileheight; // then do your blit, asumming background tiles contain all your tiles lpdds->Blt(&dest_rect, &back_groundtiles, &source_rect,(DDBLT_WAIT | DDBLT_KEYSRC), NULL);
Edited by - Leprosy on July 28, 2000 2:29:25 AM
also remember most of the time your want to use map[y][x] because arrays index the row then the column
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement