|
Destroying an array of bitmaps |
DreamCloud
Member #16,140
January 2016
|
So I'm making a game with a tiled background, and using this for it: But I get "Access Violation" when I try to destroy the bitmaps: 1for (i = 0; i < TILE_GRID_HEIGHT; i++)
2 {
3 for (k = 0; k < TILE_GRID_WIDTH; k++)
4 {
5 al_destroy_bitmap(tileVisible[i][k]);
6 }
7 }
Obviously I'm doing something wrong, but I can't figure out what.
|
Peter Hull
Member #1,136
March 2001
|
If I were a betting man, I'd guess you were destroying a bitmap more than once. In your tilemap, where you have repeated blocks, are they pointers to the same bitmap or identical copies of that bitmap?
|
DreamCloud
Member #16,140
January 2016
|
Ah, you're right. I load each different tile once separately and point to them multiple times for the map. Ugh, I can't believe I missed that. Thanks for the help!
|
duncan perham
Member #15,403
November 2013
|
You should load your bitmaps in an array. then on the map sectors you only need to store the number of the bitmap used. then when drawing, just look at the number and you will know what bitmap to draw. When loading the array, if you malloc it, you can have unlimited bitmaps, and if you save the bitmaps something like bitmap1.bmp, bitmap2.bmp ... This way, to add new bitmaps, all you have to do is drop them into the folder and your code will automatically load them and assign them a value. There are many more changes you can make to this, so that you can load related graphics, ie graphic type 1 is grass, so any graphics i call bitmap 1_X.bmp will be treated the same, so when you paste down grass, you know type 1 is grass, there might be 1 or 30 grass images, provided you also keep the frame number, you could easily do animation, or just simple random grass tiles etc. |
|