Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » I Can't stop Flicker!!

This thread is locked; no one can reply to it. rss feed Print
I Can't stop Flicker!!
Bruno Espinoza
Member #6,831
January 2006

Well, thanks for the ones that answer my last question. But... now I have other:

Basicaly, I have a class called fBackground that have two bitmaps -> The Background and the scenary. Also I have a Bitmap called 'bot' that I want to move over the another ones (Kind of GunBound game). But when I dump the images to the buffer and then to the screen I get a lot of flick!. I don't know why. You can check the source:

1#include "fbackground.cpp" //ya no incluimos allegro.h porque ya se hizo aquĆ­
2 
3int main()
4{
5 fbackground ftest;
6 int exit_n=0;
7 int my_pic_x=0;
8 int my_pic_y=0;
9 BITMAP* bot;
10 BITMAP* buffer;
11 //iniciamos Allegro
12 allegro_init(); //inicializaciĆ³n
13 install_keyboard();
14 set_color_depth(16);
15 set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);
16 bot = load_bitmap("carro.bmp",NULL);
17 if (!bot) allegro_message("No cargo... ni se porque");
18 ftest.loadbackground("background2.bmp");
19 ftest.loadmaskedbackground("background1.bmp");
20 buffer=create_bitmap(640,480);
21 while (exit_n!=1) {
22 if (key[KEY_ESC]) {
23 exit_n=1;
24 }
25 if (key[KEY_RIGHT])
26 {
27 my_pic_x++;
28 }
29 else if (key[KEY_LEFT])
30 {
31 my_pic_x--;
32 }
33 else if (key[KEY_UP])
34 {
35 my_pic_y--;
36 }
37 else if (key[KEY_DOWN])
38 {
39 my_pic_y++;
40 }
41 if (my_pic_x<0) {
42 my_pic_x=0;
43 }
44// The problematic section start here...
45 ftest.dumptobitmap(buffer);
46 draw_sprite(buffer,bot,my_pic_x,my_pic_y);
47 blit(buffer,screen,0,0,0,0,buffer->w,buffer->h);
48 clear_bitmap(buffer);
49 
50 
51 }
52 destroy_bitmap(buffer);
53 destroy_bitmap(bot);
54 return 0;
55}
56END_OF_MAIN()

It also contains some source code of the other post.

http://www.allegro.cc/files/attachment/590617 -> The Main file.
http://www.allegro.cc/files/attachment/590618 -> fBackground Declaration
http://www.allegro.cc/files/attachment/590619 -> fBackground implementation
http://www.allegro.cc/files/attachment/590621 -> .zip file with the images used.

Please help me...

A complete newbie who wants to learn something.

Kikaru
Member #7,616
August 2006
avatar

Hmmm... I don't see whats wrong yet... I use clear_to_color(), though, personally...

Do you need to use acquire/release pairs in your drawing function?

Also, try using void main() and just using a blank return; statement. Also make sure you directly include allegro.h. That's all I can see incorrect at the moment, though it most likely won't fix your problem at hand.

HardTranceFan
Member #7,317
June 2006
avatar

nm.

[edit]
To determine what's causing the flicker, have you tried alternately commenting out the lines:

  ftest.dumptobitmap(buffer);
  draw_sprite(buffer,bot,my_pic_x,my_pic_y);

[/edit]

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Onewing
Member #6,152
August 2005
avatar

Well, your problem is in ftest.dumptobitmap. I read the function and the function itself blits several things directly to the screen instead of the buffer. The only time ever anything should go to the screen is when going from the buffer to the screen (according the Theory of Double Buffering).

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Kikaru
Member #7,616
August 2006
avatar

Oh! I didn't see that in the function... ;D

HardTranceFan
Member #7,317
June 2006
avatar

Ditto. Couldn't see the wood for the trees.

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Bruno Espinoza
Member #6,831
January 2006

Thanks very much!. I didn't notice that because I was kind of sleepy at the time I wrote this code. And the last question... How can I rotate the "tank" in the map?.

A complete newbie who wants to learn something.

kazzmir
Member #1,786
December 2001
avatar

Go to: