|
al_create_sub_bitmap not working for one bitmap |
V T
Member #6,088
August 2005
|
Hello all, I am trying to use a sprite sheet for animation. I have a main bitmap that stores the sprite sheet, along with a number of bitmaps that store the individual frames of animation. I have a function called load graphics that gets called and loads the individual bitmaps as sub bitmaps of the main sprite sheet using al_create_sub_bitmap. Each frame that I load works except for one. I have an ALLEGRO_BITMAP called "* g_standing" which stores the sprite when the player is just standing still. No matter what values I pass al_create_sub_bitmap it loads the wrong frame. 1void player::load_graphics(const char * file_name)
2{
3 graphics = al_load_bitmap(file_name);
4
5 al_convert_mask_to_alpha(graphics,al_map_rgb(255,0,255));
6
7
8 g_standing = al_create_sub_bitmap(graphics,P_STAND_X,P_STAND_Y,P_STAND_W,P_STAND_H);
9
10 g_falling = al_create_sub_bitmap(graphics,P_FALL_X,P_FALL_Y,P_FALL_W,P_FALL_H);
11
12 g_walking[0] = al_create_sub_bitmap(graphics,P_WALK1_X,P_WALK1_Y,P_WALK1_W,P_WALK1_H);
13 g_walking[1] = al_create_sub_bitmap(graphics,P_WALK2_X,P_WALK2_Y,P_WALK2_W,P_WALK2_H);
14 g_walking[2] = al_create_sub_bitmap(graphics,P_WALK3_X,P_WALK3_Y,P_WALK3_W,P_WALK3_H);
15 g_walking[3] = al_create_sub_bitmap(graphics,P_WALK4_X,P_WALK4_Y,P_WALK4_W,P_WALK4_H);
16
17 curFrame = NULL;
18}
P_STAND_X = 0, P_STAND_Y = 0, P_STAND_W = 21, P_STAND_H =24, however it doesn't matter what I pass. Whatever I pass, it ends up loading the same graphic that i loaded in g_walking[2]. Even if I pass the actual numbers themselves, or even if I pass crazy numbers that couldn't possibly work. I know the line of code where g_standing is created gets called, because if I comment it out the program crashes on loading when it tries to access it. If I change the section of code that sets curFrame when the player is standing to point to another frame (say g_walking[1]) it displays that frame as it should. I can't figure out why its not working. Even stranger, if I create another bitmap variable and call it g_st, and link it the same way as g_standing, it works. I searched through every source file in my entire project for 'g_standing' to see if maybe I initilized it somewhere else by mistake somehow, but its not there. Has anyone ever seen anything like this before? I know I can just use the different variable name, however I'm interested to know why this one is giving me trouble. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
You'll have to show more code, perhaps a complete zip of src that demonstrates this and your resources. Can't tell what is going on, but it seems like memory corruption. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|