Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Animation on background

This thread is locked; no one can reply to it. rss feed Print
Animation on background
qqq m
Member #7,373
June 2006

I made animation but I want to do this animation on background picture.
but now I have black cube and not transperent in the animation background.

1 // BITMAP *First_Pic = load_bitmap("C:/Dev-Cpp/Pic/Char.bmp", NULL);
2 // masked_blit(First_Pic, screen, 0, 0, 175, 72,First_Pic->w, First_Pic->h);
3 int x=0,frame=0,f=0;
4 DATAFILE *A = load_datafile("Anim.dat");
5 // Check that the datafile was created correctly
6 if(A == NULL)
7 {
8 set_gfx_mode(GFX_TEXT,0,0,0,0);
9 allegro_message("Could not load datafile!");
10 exit(EXIT_FAILURE);
11 }
12 blit(Sec_Pic, screen, 0, 0, 144, 44,Sec_Pic->w, Sec_Pic->h);
13 while(!key[KEY_ESC]) // Keep going until we hit escape.
14{
15 while(speed_counter > 0) // Do the logic loop while the speed counter is > 0.
16 {
17 if(x==7)
18 x=0;
19 if(frame==f+5)
20 {
21 f=f+5;
22 x++;
23 }
24 frame++;
25 speed_counter --; // Decrement the speed counter.
26 }
27 if(frame<f+5)
28 draw_sprite(buffer, (BITMAP*)A[x].dat, 0, 0);
29 masked_blit(buffer, screen, 0, 0, 175, 72, buffer->w, buffer->h);//Blit the buffer
30 clear_bitmap(buffer);//Clear the buffer
31}
32 //draw_sprite(screen, (BITMAP*)A[7].dat, 40, 40);
33 // readkey();// Wait untill a key is pressed
34 
35 destroy_bitmap(buffer);
36 unload_datafile(A);
37 //destroy_bitmap(First_Pic);
38 destroy_bitmap(Sec_Pic);
39 return 0;
40
41}
42END_OF_MAIN();

Indeterminatus
Member #737
November 2000
avatar

Please, put [ code ] and [ /code ] tags around your code (without the spaces).

_______________________________
Indeterminatus. [Atomic Butcher]
si tacuisses, philosophus mansisses

BAF
Member #2,981
December 2002
avatar

[code] and [/code]

Dustin Dettmer
Member #3,935
October 2003
avatar

A few notes on your code:

 if(frame<f+5)
  draw_sprite(buffer, (BITMAP*)A[x].dat, 0, 0);
  masked_blit(buffer, screen, 0, 0, 175, 72, buffer->w, buffer->h);//Blit the buffer
  clear_bitmap(buffer);//Clear the buffer

It looks like you want some brackets for that if statement, depending on the speed that speed_counter is incremented it looks like the picture should flicker a lot or even not appear at all. Heres the code with some brackets.

 if(frame<f+5) {
  
  draw_sprite(buffer, (BITMAP*)A[x].dat, 0, 0);
  masked_blit(buffer, screen, 0, 0, 175, 72, buffer->w, buffer->h);//Blit the buffer
  clear_bitmap(buffer);//Clear the buffer
 }

You probably want to call the 'blit' function instead of the 'masked_blit' function. Unless you're doing some crazy effect with your buffer, you can make your game run make faster and respond more smoothly by replacing it with a blit. Heres how I would write the chunk of code you wrote:

 if(frame<f+5) {
  
  draw_sprite(buffer, (BITMAP*)A[x].dat, 0, 0);
  blit(buffer, screen, 0, 0, 175, 72, buffer->w, buffer->h);//Blit the buffer
  clear_bitmap(buffer);//Clear the buffer
 }

You also probably want to blit the buffer to the screen at 0,0. Heres the final code:

 if(frame<f+5) {
  
  draw_sprite(buffer, (BITMAP*)A[x].dat, 0, 0);
  blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h);//Blit the buffer
  clear_bitmap(buffer);//Clear the buffer
 }

qqq m
Member #7,373
June 2006

ty for fixed my program but you still didnt answer my question
how can I do the animation without disturbing the background ?

LennyLen
Member #5,313
December 2004
avatar

Quote:

ty for fixed my program but you still didnt answer my question

Nobody answered your question because you didn't ask a question.

Neither your original comments, nor your code snippet make it clear what you are really trying to do, or what the problem is. If you want help, you need to help others by clearly describing the problem, and what you are trying to achieve.

BAF
Member #2,981
December 2002
avatar

You can't. You have to reblit the background to the buffer each loop, before you draw the appropriate frame of the animation.

Go to: