|
|
| a5 Fade animation? |
|
Phrasz
Member #10,091
August 2008
|
So I've been trting to implement fade animation I had working in 4.22: 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: 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? Thanks in advance!
|
|
Evert
Member #794
November 2000
|
Just some general advise from me. 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: (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 Thanks!
|
|
Thomas Fjellstrom
Member #476
June 2000
|
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. -- |
|
Phrasz
Member #10,091
August 2008
|
Need Alpha Help! This is what I've devised so far: 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. -- |
|
|