|
|
This thread is locked; no one can reply to it.
|
1
2
|
| [Help] Destroy bitmaps |
|
LennyLen
Member #5,313
December 2004
|
btw, sleep is a non-standard function, so may not be supported by all C compilers. You also don't need to worry about the palette when using anything but 8 bit graphics.
|
|
jpcanaverde
Member #12,023
June 2010
|
No, the 1,2,3,4(etc) images are text. I cronometered myself reading each one, and puted the sleeptime accordinlgy. It was taking longer than the sleeptimes. So, the final code is supposed to be this, right?: 1#include <stdio.h>
2#include <allegro.h>
3
4void load_and_display_bitmap( const char* filename, int x, int y, int delay )
5{
6 BITMAP *bmp = NULL;
7 bmp = load_bitmap( filename , NULL);
8 if ( bmp )
9 {
10 draw_sprite(screen, bmp, x, y);
11 /* Consider to use rest( delay ) instead of sleep( delay ) here.
12 * rest() takes a value in milliseconds, while sleep takes seconds.
13 */
14 sleep(delay);
15 destroy_bitmap(bmp);
16 } else
17 {
18 set_gfx_mode(GFX_TEXT,0,0,0,0);
19 allegro_message("Can't load %s\n", filename);
20 }
21}
22
23int main( char** args )
24{
25 int sleepTime;
26 int bmp;
27 /* STEP 1
28 *
29 * Setup allegro, create window and init keyboard handler
30 */
31
32 /* FIX ME: Check return codes of all these functions */
33 allegro_init();
34 set_color_depth(24);
35 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
36 install_keyboard();
37
38
39
40 /* STEP 2
41 *
42 * Load the images and display them
43 *
44 * load_and_display_bitmap( filename, xPos, yPos, delay );
45 */
46 load_and_display_bitmap( "PC.bmp", 0, 255, 20 );
47
48 sleepTime=2;
49 sleep(sleepTime);
50
51 destroy_bitmap(bmp);
52
53 load_and_display_bitmap( "1.bmp", 0, 255, 20 );
54
55 sleepTime=20;
56 sleep(sleepTime);
57
58 destroy_bitmap(bmp);
59
60 load_and_display_bitmap("2.bmp", 0, 255, 20);
61
62 sleepTime=40;
63 sleep(sleepTime);
64
65 destroy_bitmap(bmp);
66
67 load_and_display_bitmap("Super.bmp", 0, 255, 20);
68
69 sleepTime=3;
70 sleep(sleepTime);
71
72 destroy_bitmap(bmp);
73
74 load_and_display_bitmap("PDA.bmp", 0, 255, 20);
75
76 sleepTime=2;
77 sleep(sleepTime);
78
79 destroy_bitmap(bmp);
80
81 load_and_display_bitmap("3.bmp", 0, 255, 20);
82
83 sleepTime=5;
84 sleep(sleepTime);
85
86 destroy_bitmap(bmp);
87
88 load_and_display_bitmap("consti.bmp", 0, 0, 0);
89
90 sleepTime=15;
91 sleep(sleepTime);
92
93 destroy_bitmap(bmp);
94
95 load_and_display_bitmap("4.bmp", 0, 255, 20);
96
97 sleepTime=22;
98 sleep(sleepTime);
99
100 destroy_bitmap(bmp);
101
102 load_and_display_bitmap("SO.bmp", 0, 255, 20);
103
104 sleepTime=10;
105 sleep(sleepTime);
106
107 destroy_bitmap(bmp);
108
109 load_and_display_bitmap("5.bmp", 0, 255, 20);
110
111 sleepTime=12;
112 sleep(sleepTime);
113
114 destroy_bitmap(bmp);
115
116 load_and_display_bitmap("6.bmp", 0, 255, 20);
117
118 sleepTime=35;
119 sleep(sleepTime);
120
121 destroy_bitmap(bmp);
122
123 load_and_display_bitmap("ubuntu.bmp", 0, 0, 0);
124
125 sleepTime=5;
126 sleep(sleepTime);
127
128 destroy_bitmap(bmp);
129
130 load_and_display_bitmap("XP.bmp", 0, 0, 0);
131
132 sleepTime=5;
133 sleep(sleepTime);
134
135 destroy_bitmap(bmp);
136
137 load_and_display_bitmap("7even.bmp", 0, 0, 0);
138
139
140 sleepTime=5;
141 sleep(sleepTime);
142
143 destroy_bitmap(bmp);
144
145 load_and_display_bitmap("7.bmp", 0, 255, 20);
146
147sleepTime=35;
148 sleep(sleepTime);
149
150 destroy_bitmap(bmp);
151
152load_and_display_bitmap("command.bmp", 0, 0, 0);
153
154
155sleepTime=3;
156 sleep(sleepTime);
157
158 destroy_bitmap(bmp);
159
160load_and_display_bitmap( "8.bmp", 0, 255, 22 );
161
162 sleepTime=22;
163 sleep(sleepTime);
164
165 destroy_bitmap(bmp);
166
167 load_and_display_bitmap( "9.bmp", 0, 0, 12 );
168
169 sleepTime=10;
170 sleep(sleepTime);
171
172 destroy_bitmap(bmp);
173
174 textout(screen, font, "Carrega em qualquer tecla para saĆr.\n", 255, 500, 255);
175
176 readkey();
177
178 return 0;
179}
180END_OF_MAIN()
It isn't the same slow, but it is slow (when I say slow, I mean it is passing the sleeptimes). Am I missing something? |
|
LennyLen
Member #5,313
December 2004
|
jpcanaverde said: So, the final code is supposed to be this, right?: The last parameter of the function Spellcaster wrote for you is the delay. Instead of passing 20 to it, and then sleeping again (say for 40s)between calls, just add the second sleep time to the first (and pass 60 to the function). You also don't need to keep destroying the bmp bitmap in the main loop, as you never even use it (you can actually remove it's declaration). Quote: It isn't the same slow, but it is slow (when I say slow, I mean it is passing the sleeptimes). Am I missing something? Sleep probably isn't very reliable. You could try using Allegro timers instead.
|
|
spellcaster
Member #1,493
September 2001
|
No, the final code is supposed to be what I posted above. Hm? And if you really want seconds, replace the call to sleep( delay ) BTW you can click any allegro and standard-c function in the code blocks here to see the man page for them, which might give you further info. -- |
|
jpcanaverde
Member #12,023
June 2010
|
Now I got it: Delay is the sleep! I didn't copy-paste your code because I thought I had to put the SleepTimes too. And it was taking too long because I was wating 2 times. OK, thank's. Now it works! Woo hoo! EDIT: It just works on my computer, with Ubuntu. I tried with Windows in a second computer and with Ubuntu on a third computer, but they don't work! I don't get it! What's happening? I really don't want to take my laptop to school... |
|
|
1
2
|