0

I have two child classes which are calling the same parent function.

One works fine, but the second call of it can't get past the al_convert_mask_to_alpha line.

I'm bamboozled once again.

Does anyone know why this may be happening?

The function below is what they both call. With the declarations of both above it.

Monster* the_monster = new Monster("chard", 10, 10, "assets/monstertrans.bmp");
Hero* the_hero = new Hero(1, "Player", 20, 20, "assets/hero.bmp");

the_monster->Display();
the_hero->Display();


void Creature::Display(void)
{
    //creating the bitmap
    al_init_image_addon(); //allegro image addon

    //FORGETTING THIS LINE WAS A SILLY IDEA!!!!
    creature_bit = al_load_bitmap(m_filename.c_str()); 

    al_convert_mask_to_alpha(creature_bit, al_map_rgb(255,0,255));

    al_draw_bitmap(creature_bit, m_xpos, m_ypos, 0);

    if (!creature_bit)
    {
        cout << "creature creation failed!" << endl;
        cout << "Any key to exit" << endl;
        _getch();
    }
}

1 Answers1

0

Your code is not organized very well.

  • Initializing the add on should only happen one time at program start
  • Loading the bitmap should happen as part of the object's constructor (or immediately after, one time only)
  • Drawing the bitmap should happen once per frame (separate from the logic of updating the creature's x/y data)

Those all belong in separate methods.

If creature_bit is null, then you should read this article as it contains everything you need to know about how to load a bitmap properly.

Matthew
  • 47,584
  • 11
  • 86
  • 98