Advertisement

PNG with allegro?

Started by December 12, 2004 03:08 PM
2 comments, last by konForce 20 years, 2 months ago
I am having trouble with my sprite in my game having a black box around him. I was told this was because he was in a bitmap image and needs to be a .png but I can't find anything in the allegro docs that will load a .png. My question is, is there anyway to load a png? If not how would I load the image so that some of it is transparent? I have also one more question, I am having trouble with collision detection and here is some of it.

typedef struct Obstruction {
    int x1, x2, y1, y2;
} Obstruction;

Obstruction one;
Obstruction two;

int SetObstruction(Obstruction obs) {
    int x1 = obs.x1;
    int x2 = obs.x2;
    int y1 = obs.y1;
    int y2 = obs.y2;
    if(char_x>=x1 && char_x<=x2 && char_y>=y2 && char_y<y2 + 10) {
        fall_point = y2 + 1;
    }
    else {
        fall_point = 192;
    }
}

SetObstruction(one);
SetObstruction(two);



When I do this it will only put the SetObstruction(two). obstruction on the map. I need to know how to make more than one instance of obstructions? [Edited by - kelcharge on December 12, 2004 3:29:08 PM]
True God of the TribunalKelchargeMy SiteMy Ugly Forums
Hey,

I'm not particularly familiar with allegro, but I just did a quick search in the docs.

You don't need to use .png. What you do need to do, however, is to know the "mask color" - or the color that will not display when drawing bitmaps.

This link:
http://www.talula.demon.co.uk/allegro/onlinedocs/en/index009.html#bitmap_mask_color

says that the mask color for truecolor bitmaps is bright pink (RGB - 255, 0, 255).
Thus, I think if you surround your image with that color and use the function
masked_blit or draw_sprite to draw your image, it won't show up.

I'm not sure if that fits all of your requirements, but it should give you a starting point to look through the documents if it's not what you need.

Could you describe your second problem a bit better? I'm not really sure what's going wrong.

Cheers,
--Brian
Advertisement
Nairb pretty much nailed how to draw transparent sprites. I will note that the main Allegro library does not handle PNG's; there's a seperate library for adding PNG support (the name escapes me at the moment). But you don't need it for this.

Jesus saves ... the rest of you take 2d4 fire damage.

For reference, you can easily load PNG files with the help of LoadPNG. It is an interface lib between Allegro and libpng. However, as the others have mentioned, your problem can be solved by using magic pink for transparency.

This topic is closed to new replies.

Advertisement