Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » bitmap layering

Credits go to Dizzy Egg, Jeff Bernard, and pkrcel for helping out!
This thread is locked; no one can reply to it. rss feed Print
bitmap layering
ioncherry
Member #15,057
April 2013

Hello there fellow allegroids!

I was wondering if you could clear a couple of things up for me - firstly, is there a way to chose what layer your bitmap is on, so can I set it so that a certain bitmap is shown above another which is called later on in the program? - I ask this because as part of my game half way through I clear a bitmap to transparent colour, only problem is when objects go over this space the objects are going behind the white colour instead of infront!

A second query I have is the following - Is there a way when blitting multiple of the same bitmaps to set it so that each different blit is defined to it's own value so that the you can destroy one but not the other.

For example if I was to do the following:

         blit( image, buffer, 0, 0, 500, 200, image->w, image->h );
         blit( image, buffer, 0, 0, 500, 400, image->w, image->h );

and I was then to call destroy_bitmap(image); both images would be destroyed.

I would like it so that they can be each individually assigned so I can do different things to them whilst using the same bitmap.

Thank you in advance and I apologise if that was a really over explained version of a simple question!!

Jeff Bernard
Member #6,698
December 2005
avatar

ioncherry said:

is there a way to chose what layer your bitmap is on, so can I set it so that a certain bitmap is shown above another which is called later on in the program?

Bitmaps are drawn in the order you call blit. So for that, I'd implement a deferred drawing system. Instead of calling blit like you normally would, you'd push some object representing the draw into a sorted list. Then you just iterate through the list. If your objects aren't going to be changing layers, then you won't need to update these list every tick, only when things should be removed/added.

Quote:

Is there a way when blitting multiple of the same bitmaps to set it so that each different blit is defined to it's own value so that the you can destroy one but not the other.

No... but you could load the same bitmap twice for some reason? If you want to not draw one of them, then don't draw one of them, destroy_bitmap does not erase a bitmap from the screen.

--
I thought I was wrong once, but I was mistaken.

ioncherry
Member #15,057
April 2013

Thank you for the reply,

Ahh okay - well I've sorted the layering now so thank you!

Does this mean I'm going to have to make multiple of the same bitmap files and rename them differently and blit them all seperately then if I want to do different things to them?

Cheers

Dizzy Egg
Member #10,824
March 2009
avatar

Nope. Have 1 bitmap file on your computer, and load it into as many different ALLEGRO_BITMAPS as you want!

ALLEGRO_BITMAP *bitmapA = load_bmp("myOneBitmap.bmp", NULL);
ALLEGRO_BITMAP *bitmapB = load_bmp("myOneBitmap.bmp", NULL);
ALLEGRO_BITMAP *bitmapC = load_bmp("myOneBitmap.bmp", NULL);
ALLEGRO_BITMAP *bitmapD = load_bmp("myOneBitmap.bmp", NULL);
ALLEGRO_BITMAP *bitmapE = load_bmp("myOneBitmap.bmp", NULL);
ALLEGRO_BITMAP *bitmapF = load_bmp("myOneBitmap.bmp", NULL);

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

pkrcel
Member #14,001
February 2012

Or load once and then al_clone_bitmap...or whatever your resource management style implies. :)

(Of course this post and Dizzy's refer(s) to Allegro5 API. :P ..gotta check beter next time).

It is unlikely that Google shares your distaste for capitalism. - Derezo
If one had the eternity of time, one would do things later. - Johan Halmén

ioncherry
Member #15,057
April 2013

Thanks so much guys! Dizzy got it spot on :D - Also thank you pkrcel - it's my fault I didn't mention that I'm using allegro 4, otherwise that would of been perfect as well!! Cheers all

Go to: