1
I’m trying to create a game in Allegro 4
, but I am having problems with a method, more specifically with an attribute BITMAP
. The program compiles but stops working right away. Follow the code:
#ifndef INSTANCE_H
#define INSTANCE_H
#include "global.h"
class Instance{
public:
Instance(bool random);
void setTexture(string local);
int getPositionX();
int getPositionY();
void drawOnBuffer(BITMAP *buff);
private:
int x;
int y;
BITMAP *texture;
};
#endif
When calling the method setTexture
, the program stops working. I believe the problem is occurring because the Texture attribute is a pointer, but I am beginner in object orientation and still can’t solve. The implementation I did was as follows:
void Instance::setTexture(string local){
texture = load_bitmap(&local[0], NULL);
}
In main, I create the object and pass the name of the arquivo bitmap
to be opened:
Instance pokeball(true);
pokeball.setTexture("pokeball.bmp");
Remembering that the problem is when assigning a value to the Texture attribute. Whenever I remove it from the code, everything works normally.