Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » draw_sprite in allegro 5

Credits go to Edgar Reynaldo, Evert, jmasterx, Matthew Leverton, and Thomas Fjellstrom for helping out!
This thread is locked; no one can reply to it. rss feed Print
draw_sprite in allegro 5
jim109109
Member #14,273
May 2012

Hello, I'm new to Allegro and learning the functions gradually as I need them. Everything seemed great..until now...My first problem

I need to draw a bitmap on top of another. I have found the allegro 4 "draw_sprite" function which seems to do the trick. The problem is I can't seem to find the equivalent in allegro 5...

I get:
identifier "al_draw_sprite" is undefined
or
identifier "draw_sprite" is undefined

Same error for blit() and a couple of similar functions.
Other functions & the tutorial worked.

Are those particular functions obsolete in allegro 5?
Or is there a specific header that I need to include?

Thanks! ;D

Matthew Leverton
Supreme Loser
January 1999
avatar

Use al_draw_bitmap() with an image that has an alpha channel.

jim109109
Member #14,273
May 2012

That is hardly as convenient...then i have to handle the images one by one.
I have a map composed of tiles. I want the map to be a bitmap, and to draw the tiles over it.
That way, when I move the camera, I don't have to redraw all the tiles but rather draw a different segment of the map. It will make the game run faster.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

jim109109
Member #14,273
May 2012

But can it draw on another bitmap rather than the actual display? :O
*Really the problem with drawing on display is that I wanna store the resulting image in a variable for further use, manipulation, etc, for example drawing a sub bitmap

Thanks men

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

jmasterx
Member #11,410
October 2009

al_set_target_bitmap should do it for you.

D'Oh, beat me to it.

jim109109
Member #14,273
May 2012

That is exactly what I'm look for! Thank you!
I will surely include you in the
May the heavens shine upon you who made this badass game possible
section of the CREDITS!

Evert
Member #794
November 2000
avatar

jim109109 said:

I have a map composed of tiles. I want the map to be a bitmap, and to draw the tiles over it.
That way, when I move the camera, I don't have to redraw all the tiles but rather draw a different segment of the map. It will make the game run faster.

I would not be so sure of that, especially if the map is large. By all means try it though.

Thomas Fjellstrom
Member #476
June 2000
avatar

Drawing to bitmaps and "double buffering" like that is likely to be slower than just drawing directly to the screen. You can't think of allegro 5 behaving anything like allegro 4 performance wise. They are completely different. Essentially, the most compatible and fastest way to draw in A5 is to just dump everything directly to the screen, optionally skipping stuff that just gets overdrawn later (though that may not matter much with a simple 2d game).

One tip for a5 is to put all of your tiles and sprites into a single bitmap (aka: an atlas) and then wrap all of the drawing of the items in that atlas in al_hold_bitmap_drawing calls. It's an implementation detail, but a fairly important one. This way allegro won't needlessly change the texture state, and it'll hold all of the drawing till you unhold the drawing, so it gets transferred in one large blob. It can mean a significant speed up for things like tile maps.

Note, some systems may not support drawing to textures, or if they do, it'll be quite slow. Something to watch out for.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

jim109109
Member #14,273
May 2012

I will probably try both methods and let you know which is faster.

Here's how I would go about drawing tile by tile (correct me if wrong):
- Have a tileset loaded in memory
- Use create_sub_bitmap to load each tile [once on map load]
- Redraw the tiles where needed in viewable screen with each movement of character

or
- Create a new sub_bitmap per tile at each change in camera with al_hold_bitmap_drawing to not duplicate load

*The way my camera will be setup, every movement will alter the camera and the tiles will have to be redrawn.

====================================

UPDATE:
Exciting days are here! The test results are in!

Both draw methods have an execution time of 0.001 seconds! Therefore, any of the two are viable.

However, drawing the whole map beforehand uses up MORE MEMORY and has an initial load of 0.019 seconds [on map load]!

Drawing tiles directly on screen is ALSO independent of map size. For these reasons, I will use that method!

Thank you for the valuable help, my questions have hereby been FULLY ANSWERED TO MY SATISFACTION!

Go to: