|
drawing sprite sheet frames ? |
Mueble
Member #15,827
December 2014
|
BITMAP *grabframe(BITMAP *source,int startx,int starty,int width,int height,int frame,int columns) Hi guys I'm using this function to fill an array of bitmap which then I can use for drawing frames.Is there a drawback from doing this? It seems intuitive to me but the majority of other methods that I've seen use the sprite sheet and then calculate the position of a given frame in order to draw it. What would be the advantage of doing that? |
Thomas Fjellstrom
Member #476
June 2000
|
If you call your function a lot, you'll be creating a ton of new bitmaps. It's a lot of churn. One option is to just draw out of it directly as you mentioned, or create a sub bitmap instead. And hopefully you're storing them some place, and not calling that function over and over in your drawing code -- |
Edgar Reynaldo
Major Reynaldo
May 2007
|
As Thomas said, you may want to use sub-bitmaps. It reduces your code to : BITMAP *grabframe(BITMAP *source,int startx,int starty,int width,int height,int frame,int columns) { int x = startx + (frame %columns)* width; int y = starty + (frame /columns) * height; BITMAP* frame = create_sub_bitmap(source , x , y , width , height); return frame; } This allows you to keep all your frames on the same sprite sheet, which can then be used as an atlas. You draw everything from this sheet in one batch if possible, using al_hold_bitmap_drawing. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Thomas Fjellstrom
Member #476
June 2000
|
Edgar Reynaldo said: This allows you to keep all your frames on the same sprite sheet, which can then be used as an atlas. You draw everything from this sheet in one batch if possible, using al_hold_bitmap_drawing. Keep in mind that the OPs code is Allegro 4 which doesn't have held drawing. -- |
Edgar Reynaldo
Major Reynaldo
May 2007
|
I need to pay more attention.... I knew it was allegro 4, but I gave A5 advice too. Whoops. Sorry bout that. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|