Problem with Allegro 4 and C++

Asked

Viewed 87 times

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.

1 answer

1


See if that’s not it:

void Instance::setTexture(string local){ texture = load_bitmap(local.c_str(), NULL); }

So you pass the std::string "translated" to the const char *

Browser other questions tagged

You are not signed in. Login or sign up in order to post.