what is wrong with this code?? the sprite doens't show up on the screen, i checked the source and the .bmp's and i don't understand why the sprite doens't show on the screen, there is just a black screen.
1 | #include <allegro.h> |
2 | #include <vector> |
3 | |
4 | using namespace std; |
5 | |
6 | |
7 | |
8 | |
9 | int main() |
10 | { |
11 | allegro_init(); |
12 | install_timer(); |
13 | install_keyboard(); |
14 | set_color_conversion(COLORCONV_TOTAL); /* this is the new line */ |
15 | set_color_depth(16); |
16 | set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); |
17 | |
18 | |
19 | |
20 | |
21 | // Pass NULL to use default pallete |
22 | BITMAP *goku = load_bitmap("1.bmp", NULL); |
23 | if (!goku) |
24 | { |
25 | allegro_message("error: could not load 1.bmp"); |
26 | } |
27 | BITMAP *gokus = load_bitmap("2.bmp", NULL); |
28 | if (!gokus) |
29 | { |
30 | allegro_message("error: could not load 2.bmp"); |
31 | } |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | vector<BITMAP*> fighter; |
39 | fighter.push_back(goku); |
40 | fighter.push_back(gokus); |
41 | |
42 | vector<BITMAP*>::iterator iter = fighter.begin(); |
43 | |
44 | |
45 | while( !key[KEY_ESC] ) |
46 | { |
47 | |
48 | |
49 | if (key[KEY_S]) |
50 | { |
51 | if ( iter != fighter.end() -1 ) |
52 | { |
53 | ++iter; |
54 | } |
55 | } |
56 | else if (key[KEY_A]) |
57 | { |
58 | if ( iter != fighter.begin() ) |
59 | { |
60 | --iter; |
61 | } |
62 | } |
63 | |
64 | } |
65 | |
66 | |
67 | |
68 | acquire_screen(); |
69 | |
70 | blit( *iter, screen, 0, 0, 0, 0, (*iter)->w,(*iter)->h ); |
71 | |
72 | release_screen(); |
73 | rest(50); |
74 | |
75 | |
76 | |
77 | |
78 | destroy_bitmap(goku); |
79 | destroy_bitmap(gokus); |
80 | |
81 | |
82 | return 0; |
83 | } |
84 | |
85 | END_OF_MAIN() |
blit( *iter,...
I'm not sure that allegro is able to blit that , but i'm noob at c++ purpose.
Because you draw only after the main loop and only let the sprite stay on the screen for 50 ms.
He isn't clearing the screen, it should be right for that.
EDIT: And I think He could throw this "rest(50)" line.
He will have better results using QueryPerformanceCounter and an adapted loop.
GullRaDriel: You're missing the point. He's asking why he gets a black screen. The answer is because he doesn't draw anything in the main loop.
Ho YES ! He didn't put the blit in the loop !
I was thinking ( affected by some strange spell ) it was in :p
EDIT:
1 | #include <allegro.h> |
2 | #include <vector> |
3 | |
4 | using namespace std; |
5 | |
6 | |
7 | |
8 | |
9 | int main() |
10 | { |
11 | allegro_init(); |
12 | install_timer(); |
13 | install_keyboard(); |
14 | set_color_conversion(COLORCONV_TOTAL); /* this is the new line */ |
15 | set_color_depth(16); |
16 | set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); |
17 | |
18 | |
19 | |
20 | |
21 | // Pass NULL to use default pallete |
22 | BITMAP *goku = load_bitmap("1.bmp", NULL); |
23 | if (!goku) |
24 | { |
25 | allegro_message("error: could not load 1.bmp"); |
26 | } |
27 | BITMAP *gokus = load_bitmap("2.bmp", NULL); |
28 | if (!gokus) |
29 | { |
30 | allegro_message("error: could not load 2.bmp"); |
31 | } |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | vector<BITMAP*> fighter; |
39 | fighter.push_back(goku); |
40 | fighter.push_back(gokus); |
41 | |
42 | vector<BITMAP*>::iterator iter = fighter.begin(); |
43 | |
44 | |
45 | while( !key[KEY_ESC] ) |
46 | { |
47 | |
48 | |
49 | if (key[KEY_S]) |
50 | { |
51 | if ( iter != fighter.end() -1 ) |
52 | { |
53 | ++iter; |
54 | } |
55 | } |
56 | else if (key[KEY_A]) |
57 | { |
58 | if ( iter != fighter.begin() ) |
59 | { |
60 | --iter; |
61 | } |
62 | } |
63 | acquire_screen(); |
64 | |
65 | blit( *iter, screen, 0, 0, 0, 0, (*iter)->w,(*iter)->h ); |
66 | |
67 | release_screen(); |
68 | rest(50); |
69 | } |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | destroy_bitmap(goku); |
79 | destroy_bitmap(gokus); |
80 | |
81 | |
82 | return 0; |
83 | } |
84 | |
85 | END_OF_MAIN(); |
Now this should work !
i did put the blit in the loop..its in a while loop
No, it isnt. Only your input is in the loop.
ahhhh, ok
wow, all of the nested if and loops and whiles, that was crazy, thank you all so much
im such an idiot for not seeing that
im such an idiot for not seeing that
Don't be too hard with yourself. I remember having doing such things and more :-p
Which editor do you use to write your code? I though every decent editor higlights your loops and things like that so it's easy to see what goes where...
That's how Scite does, for example.
DevCpp isn't (Or i don't found how)
devcpp can highlight matching braces too. It was somewhere in the editor options
Notepad however doesn't
Hey Money...
I think that set_color_conversion is also in the wrong order, it should be:
allegro_init(); install_timer(); install_keyboard(); install_mouse(); set_color_depth(32); set_gfx_mode(GFX_AUTODETECT,800,600,0,0); set_color_conversion(COLORCONV_TOTAL);
I'm not exactly sure that it needs to be in that order, but it works fine for me.
Doesn't matter when you call set_color_conversion, as long as it's after allegro_init() and before loading the bitmap or datafile.