Allegro bitmaps at runtime?

Started by
1 comment, last by Soundstone 10 years, 2 months ago

Hello everyone,

I have recently run into a problem that I'm not sure Allegro 5 can handle. I was curious if anyone knew whether or not the following functionality existed for the Allegro graphics library.

I am aware that to get a scrolling background one can provide an image and load it in as a ALLEGRO_BITMAP *background. I have done this just fine. However, for the particular game I am trying to code I generate the level at random.

Basically I generate two arrays of points, one for my ceiling and one for my floor. These arrays are size top[333] and bottom[333]. The distance between each point is between 36 - 48 pixels, thus my final point in both arrays is someone just over 12,050 as the X coord.

My question is this, does Allegro have a way to create an image at runtime based on the plot placement of these randomly generated points?

I've tried looking at the Allegro5 manual and it doesn't really provide any information on bitmap creation at runtime. Does anyone have experience with this sort of thing, or am I doomed to choose a new graphics library or create static images instead of random?

Thanks for taking the time to read and any advice that may be offered.

Advertisement
Sure; first, create a BITMAP. Then, lock your new bitmap and set the target bitmap. You then can use any of the drawing operations such as al_put_pixel or al_draw_bitmap to draw to your dynamically created bitmap. Don't forget to unlock the bitmap when you're done. Remember that creating bitmaps are expensive operations, so use al_clear_to_color on the same bitmap instead of creating it each frame, if needed.

Note: It's been a quite a few years since I've touched Allegro, so I might not be quite accurate.

Hi Fastcall,

Thanks for the reply! The information was a relief to hear. Would you recommend printing the entire thing to one bitmap and then drawing a region of that bitmap with al_draw_bitmap_region() or just keep a bitmap the size of my screen and keep clearing / drawing the new sets of points to it before blitting to the display? Thanks again.

This topic is closed to new replies.

Advertisement