# Allegro : problem with sprites

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

## Recommended Posts

OK so this is a real stupid question from a total Allegro newbie (I've been using SDL for a while but I read somewhere that Allegro could be used for GBA dev.. and I just bought myself an SP). SO... the problem is that everytime I use the draw_sprite() function, the image that's displayed is just a big navy blue rectangle. I've tried messing with color depths, gfx modes, number of colors in the sprites. Actually if I decrease the sprites' color depth to 256, the picture is displayed on the screen but the colors are all messed up. What am I doing wrong? Do I need to call some magic function or something? (right now I'm only using the load_bitmap("sprite.bmp", NULL); and draw_sprite([...]); functions). Thanks in advance!

##### Share on other sites
I think I have an idea; I recall doing the same thing once. [smile] Code snippet pls?

##### Share on other sites
Make sure you set the color depth and graphics mode before loading images. Regarding GBA development, I don't really see how Allegro will help you there.

##### Share on other sites
What is the color depth of your bitmap you are loading? If it's 24bit and you set the color depth to 32 in allegro it should work fine.

##### Share on other sites
If you want to use an 8bpp bitmap, you have to load its pallete (sp?) (use load_bitmap("blah.bmp", pal), where pal is a PALLETE struct).

All in all, it is much easier to use high-color modes rather than palleted ones until you get used to it. Just call set_color_depth(32) (or 16), before setting the gfx mode, and you will be able to use both high color and palletted bitmaps (at a speed hit of course).

PS: Are you sure there is a GBA port of Allegro? It's the first time I've ever heard of this (and sure enough, there is no mention of this in the docs or the developer's mailing list).

##### Share on other sites
It would help to see your code, but here is my two cents.
draw_sprite is just masked_blit. It is expecting your image to have an alpha layer, I think. This means, a background that is all pink(ff00ff)That's pink right? So, when it draws the sprite it will leave out all the pink, and just draw your hero, or sprite, whatever.

Here is some code:

allegro_init();	BITMAP *guy;set_color_depth(16);		set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);	install_keyboard();        guy = load_bitmap("guy.bmp", NULL);        draw_sprite(buffer, guy, SCREEN_W/2, SCREEN_H/2);		blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

That should give you a general idea of how draw_sprite should be used. Make sure you set your color depth before set_gfx_mode, I have had that problem before.

And again, it's expecting you to have an Alpha layer, or, pink background. Sorry if my terminolgy is wrong here.

Does this help?

##### Share on other sites
Just found what was the problem... I was loading the sprite before setting the graphic mode.

As for GBA dev, I think you're right konForce... I misread the sentence that made me think that Allegro could be used for GBA dev. All it said was to use Allegro to GET USED to gfx programming or something.

##### Share on other sites

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

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628736
• Total Posts
2984456

• 25
• 11
• 10
• 16
• 14