Drawing a map (from a matrix)

Started by
4 comments, last by ANTnet 20 years, 11 months ago
Hi I have a matrix which represent my map: int map[20][20]; I do 2 for() to draw the whole map. if 0 > im1.bmp if 1 > im2.bmp... how do I have to proceed: do I have to load each image im1.bmp, im2.bmp... before drawing even if some bitmaps are useless on this part of the map that will be shown on the screen? Or do I have to load it each time I need it... hm I don''t think so, but loading all in mem before using it is not too big for the mem? my images are 32x32 images... thanks ANT
Advertisement
You''re making it obscure for any reader out there, but to answer to your last question, nope, it''s not too big for the memory in any case. (your question is far too vague).
You could always loop through the matrix and check so if you don''t have a certain bitmap code int the array you don''t load it into memory.

I''m not sure what you mean, but you don''t have to reload a bitmap to a surface/buffer between blitting calls if that is what you mean.
--------------------Though this program be madness, yet there is a method in't
I have a matrix

000...0012021110
00111...21451000
...

0: image1.bmp
2: image2.bmp
3: image3.bmp

how do I display my map: do I have to load before scanning the matrix item by item all the bmps? or do I have to load the bmp each time I have its corresponding number?
load them all (or at least the ones you use) beforehand, so you only have to look them up when drawing (otherwise it will be very slow)...

it would be better overall if you put all the tiles into one bitmap though, and just blit the appropriate piece each time.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
i myself just finished creating a tile display. what you do is you have a structure for your tiles, with coordinats on the map and coordinates on your chipset (all of your images are in one file). when looping through the file and getting the information, you obtain the x and y coordinate of the image you are using in the chip set (much like it would be on your map), and then you get the souce rectangle (or square in this case) by multiplying the x and y chip coordinates by the cell width and height, this will get you the image. ou only have to load one image, once.

----------------------
i code therefore i am.

Aero DX - Coming to a bored Monitor near you!
----------------------i code therefore i am.Aero DX - Coming to a bored Monitor near you!

This topic is closed to new replies.

Advertisement