Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » a5 Fade animation?

This thread is locked; no one can reply to it. rss feed Print
a5 Fade animation?
Phrasz
Member #10,091
August 2008

So I've been trting to implement fade animation I had working in 4.22:

#SelectExpand
1void show(BITMAP *bmp, int speed=2) 2{ 3 BITMAP *transfer; 4 int alpha; 5 6 transfer = create_bitmap(SCREEN_W, SCREEN_H); 7 masked_blit(screen, transfer, 0, 0, 0, 0, SCREEN_W, SCREEN_H); 8 9 // fade it in on top of the previous picture 10 for (alpha=0; alpha<256; alpha+=speed) 11 { 12 set_trans_blender(0, 0, 0, alpha); 13 draw_trans_sprite(transfer, bmp, (SCREEN_W-bmp->w)/2, (SCREEN_H-bmp->h)/2); 14 vsync(); 15 masked_blit(transfer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); 16 } 17 destroy_bitmap(transfer); 18}

The gist of it was to send a bitmap, assuming it may be the old "magic pink" type to the screen in increased blending levels of the alpha. (the for loop variable steps up and so does the blender alpha level)

Now I have been trying to do the same idea with some of the following code:

#SelectExpand
1 int alpha; 2 3 transfer = al_create_bitmap(al_get_display_width(display), al_get_display_height(display));//SCREEN_W, SCREEN_H); 4 5 int speed=1; 6 7 // fade it in on top of the previous picture 8 for (alpha=0; alpha<256; alpha+=speed){ 9 al_set_blender(ALLEGRO_ADD, alpha, 256-alpha); 10 al_set_target_bitmap(transfer); 11 al_draw_bitmap(bitmap, 0, 0, 0); 12 al_set_target_backbuffer(display); 13 al_draw_bitmap(bitmap, 0, 0, 0); 14 }

Take away's:

1) Assume the ALLEGRO_DISPLAY is named "display" and that bitmap (seen in the first draw bitmap) is the desired bitmap to fade in.

2)I understand the desire to lock bit maps or use memory bit maps, but I am still learning this new implementation in a5, so forgive me for any noob code mistakes.

Help?
What I would appreciate is either a)help with the a5 code above to fix it, or b)a point in the direction to find bitmap fading/animation information.

Thanks in advance!
-Phrasz

Evert
Member #794
November 2000
avatar

Just some general advise from me.
First of all, don't change drawing targets. It's almost certainly more efficient to just draw to the backbuffer of the current display. You don't need memory bitmaps and you don't need bitmap locking (in fact, you shouldn't use either).

The way I would go about doing what you're trying to do is this: first, get a copy of the current image (the front buffer). Then in your fade-in loop, first blit that one (directly), then blit the image you're fading to (with appropriate alpha).

Finally, don't forget to call al_flip_display() to actually see the results.

(By the way, you didn't make it clear what you thought was wrong with the code you posted in the sense of saying what you want it to do and saying what it does instead).

Phrasz
Member #10,091
August 2008

Ha! Thanks for the fast reply. I am currently attempting to take your suggestions and implement them in some kind of code...

As for what I am trying to do:
I wish to have a simple fade animation using a temporary bitmap buffer and a processing a desired "fade in" bitmap.
This is what I tried to do:
1)Create the bitmap transfer as to use as a buffer
2)have a variable called speed so I can later use it to determine the quickness, or speed, of the fade transition.
3)Enter the for loop for the steps of the fade in (I assume I have to have a sequence of slowly fade in drawings of the desired bitmap.)
3.1)The loop should copy the screen to transfer, and them attempt to draw in the desired bitmap on top of the existing data in gradual alpha steps. IE copy the display, draw the display, apply alpha settings, draw the desired fade in bit map with the new fade/alpha.

(The code currently is WAY wrong since it's attempting to copy the bitmap to transfer, then attempts to draw the bit map to the screen. I do nothing with transfer nor the current display.)

I will give the caveat I am a hardware guy trying to messing around and make games in his spare time :). So again if I make crazy mistakes: expect them from me.

Thanks!

Thomas Fjellstrom
Member #476
June 2000
avatar

I believe there is no need to have a temporary bitmap. Might not be correct, but try blitting your bitmap unmodified to the display, then set the blender to alpha blend, then draw a black rectangle with an alpha of whatever the opacity/translucency of the fade you want over top.

Should be many times faster than using a temporary bitmap.

--
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

Phrasz
Member #10,091
August 2008

Need Alpha Help!

This is what I've devised so far:

#SelectExpand
1 al_clear_to_color(al_map_rgb_f(0, 0, 0)); 2 for(int fadeloop=0; fadeloop<256; fadeloop+=speed){ 3 al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, ALLEGRO_ADD, fadeloop,ALLEGRO_ZERO); 4 al_draw_bitmap(bitmap,0,0,0); 5 al_flip_display(); 6 }

I'm trying to create a black screen (see clear to color), and then incrementally increase the alpha blending. I'm attempting this so when I draw the to screen a bit more of the desired "fade in" bitmap is shown.

However, I just get a flashing image at the conclusion of the for loop execution.

Suggestions? Fixes?

Thanks in advance!

Elias
Member #358
May 2000

Try something like this:

            al_clear_to_color(al_map_rgb_f(0, 0, 0));
            for(int fadeloop=0; fadeloop<256; fadeloop+=speed){
                al_draw_tinted_bitmap(bitmap,al_map_rgba_f(1,1,1,fadeloop/255.0)0,0,0);
                al_flip_display();
                al_rest(0.1);
            }

You only need to change the blender if you want something different from alpha blending, but from what I understand alpha is what you want.

--
"Either help out or stop whining" - Evert

Go to: