Jump to content
  • Advertisement
Sign in to follow this  
GKANG

Trouble with getting a BITMAP from a class (Allegro

This topic is 2226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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. Edited by GKANG

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!