![]() |
|
Bitmap array |
Ceagon Xylas
Member #5,495
February 2005
![]() |
Now I know 24,467 people have asked how to do this or have been shown how to do this -- but when I finally can't remember how to, the Allegro search completely fails me. How on earth do you load into a BITMAP* array?! BITMAP *sprite_g[255]; main() { sprite_g[0]=load_pcx("file.pcx",NULL); sprite_g[1]=load_pcx("file.pcx",NULL); draw_sprite(buffer,sprite_g[0],0,0); draw_sprite(buffer,sprite_g[1],320,0); for(int i=0; i<255; i++) destroy_bitmap(sprite_g<i>); } This is crashing for me every time. Checked my file paths, they're correct. I can get this to work: for(int i=0; i<255; i++) { sprite_g<i>=create_bitmap(20,20); clear_to_color(sprite_g<i>,makecol(255,255,255)); } draw_sprite(buffer,sprite_g[0],0,0); But whenever I load the file into the array it's not workin'. |
miran
Member #2,407
June 2002
|
1. Initialize bitmaps to 0 before loading. Note: #3 may not be necessary. -- |
ReyBrujo
Moderator
January 2001
![]() |
If your code, you load two bitmaps, all the other positions have trash since they aren't initialized. At the end of the program you try to destroy 256 bitmaps, but only two have been allocated. Probably when i = 2 destroy_bitmap crashes. (Plus miran's suggestions, of course) -- |
Ceagon Xylas
Member #5,495
February 2005
![]() |
It's crashing on the draw_sprite() function almost certainly. The reason I say that is because it runs fine until I press 'a' in this program: //declare bitmaps main() { while(!end_program) { if(key[KEY_A]) draw_sprite(buffer,sprite_g[0],0,0); //blit the buffer } //destroy_bitmap for loop } I'll try what you said, miran. [edit] |
miran
Member #2,407
June 2002
|
Yay! -- |
A J
Member #3,025
December 2002
![]() |
Quote: It's crashing on the draw_sprite() function almost certainly. ALMOST What do you mean almost, dont you know ? Do you know how to use a debugger ? ___________________________ |
CGamesPlay
Member #2,559
July 2002
![]() |
More importantly, initialize allegro! -- Ryan Patterson - <http://cgamesplay.com/> |
|