C++ Allegro 位图子类
C++ Allegro Bitmapping Child Classes
我有两个子类调用同一个父函数。
一个工作正常,但它的第二个调用无法通过al_convert_mask_to_alpha
行。
我又一次被迷惑了。
有谁知道为什么会发生这种情况?
下面的函数是它们都调用的函数。上面都有两者的声明。
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();
}
}
你的代码组织得不是很好。
- 初始化附加组件应该只在程序启动时发生一次
- 加载位图应作为对象构造函数的一部分进行(或紧随其后,仅一次)
- 绘制位图应该每帧发生一次(与更新生物的 x/y 数据的逻辑分开)
这些都属于不同的方法。
如果creature_bit
是null
,那么您应该阅读本文,因为它包含您需要了解的有关如何正确加载位图的所有信息。
相关文章:
- 继承期间显示未知行为的子类
- C / C++ 移位/偏移/向左或向右移动位图?
- 通过指向指针数组的指针访问子类的属性
- 从父类方法返回子类对象
- c++, 在子类中,如何在没有对象的情况下访问父类的方法?
- 将父类对象强制转换为子类的问题
- 避免在C++中重复子类定义
- 将QOpenGLWidget子类转换为使用Metal而不是OpenGL的子类是否可行?
- 如何初始化矢量的模板化子类
- C++ 继承:将子类传递给需要基类的函数并获取子类行为
- 有没有办法按值将纯抽象类的所有子类传递给 C++ 中的函数?
- 使用子类覆盖基类中定义的函数
- 子类地址等于虚拟基类地址?
- 将子类方法声明为基类的友元
- 如何在快板的屏幕中显示子位图的绘制?
- 来自程序子窗口的位图返回为黑色
- 带有ATL子类的Windows 10 64位上的随机崩溃
- C++ Allegro 位图子类
- wx位图按钮读取类参数
- 用于位图管理的C++STL类