Trouble with getting a BITMAP from a class (Allegro

Started by
0 comments, last by GKANG 11 years, 8 months ago
I'm trying to make an Actor class, where in the constructor I send in a file location for the bitmap. Then I want to use a GetSprite() function to return the BITMAP and use it in the blit() function to draw it to the screen. I get no errors, but the program crashes immediately. I think this is because the image isn't being put into the address where the BITMAP *Sprite points to, but maybe not I dunno. My function call was something like: Actor Guy("image.bmp");

I ended up changing my approach since this ended up just not working, and decided to instead send in an enum. With the enum (eg. INVADER), I was going to use a switch statement in my constructor to assign the correct image there, meaning that there were no mistakes when sending in a file location when creating the object.

Here's the code:

[source lang="cpp"]class Actor
{
public:
Actor(int a, int b, TEAM Type) : HP(a), Speed(b)
{
switch(Type)
{
case INVADER: Sprite = load_bitmap("invader.bmp", 0); break;
case PLAYER : Sprite = load_bitmap("player.bmp", 0); break;
}
}
void Move() { PosX += Speed; }
void Draw() { blit(Sprite, screen, 0, 0, 0, 0, ScreenHeight, ScreenWidth); }
private:
BITMAP *Sprite;
int PosX, PosY, HP, Speed;
};[/source]

This just doesn't work, though. If I comment out the call to Draw() in my main loop the program runs and exits fine. When I try to Draw though, it crashes just like before.

What's going on, I'm kinda lost.
Advertisement
I made thread after about an hour of trying to figure this out, then I figure it out within 2 minutes of posting. I said it's probably that the files aren't being loaded, well, they weren't. Incorrect filenames.

This topic is closed to new replies.

Advertisement