Who can tell me how to show the transparent sprite?
The sprite bitmap has a PINK(255,0,255) bg color, and my backbuff is black,
I want that when the sprite is drawn onto the backbuff, his bg color becomes BLACK color. what should I do ? my code doesn't work at all. look:
|6|| BITMAP* backbuff;|
|7|| BITMAP* sprite;|
|8|| DATAFILE* data;|
|13|| set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);|
|14|| backbuff = create_bitmap(800, 600);|
|15|| clear_to_color(backbuff, makecol(0,0,0));|
|16|| data = load_datafile("haphi.dat");|
|17|| sprite = (BITMAP*)data[WALK_RIGHT].dat;|
|18|| masked_blit(sprite, backbuff, 0, 0, 200, 300, sprite->w, sprite->h);|
|19|| blit(backbuff, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);|
|23|| return 0;|
It doesn't work because you saved the image as a JPEG, which compresses colors, and only the magic pink (255, 0, 255) is transparent in allegro... or black in 8 bpp.
At least that's how it looks on the screenshot.
Save the image as either a bmp or a png, and it should work fine.
NO, the image in the post is just my screen-save, in my program, the sprite image
is indeed a BMP file stored in a *.dat file.
I use this to get it: BITMAP* sprite = (BITMAP*)data[WALK_RIGHT].dat;
I have used masked_blit(), but it still doesn't work.:-/
Download attachment..my dat resource file in it. thanks.
The sprite bitmap has a PINK(255,0,255) bg color
I don't think I have the grabber atm, but I can see that it's not pure magic pink, because the top of the image is black, and the rest is not. Did you convert the sprite from a jpg or gif, perhaps?
In that case, a solution would be to use MS Paint and paint the background again (preferably using the erase tool).
Thread #587580. Printed from Allegro.cc
Just Now , I use photoshop7.0 to check the BMP file RGB value and found that some area is (252,2,252) ,some area is (255,0,255), OH, my god......
I got these resource files from internet, after that , I clipped them and added them into a *.dat file, I think I broke their original quality. so that's why the top of the sprite's background color is BLACK, it puzzled me quite a while....