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 | |
3 | int 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 | } |
56 | END_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...
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.
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]
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).
Oh! I didn't see that in the function...
Ditto. Couldn't see the wood for the trees.
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?.