Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Sleep( ); Function not working

Credits go to Trent Gamblin for helping out!
This thread is locked; no one can reply to it. rss feed Print
Sleep( ); Function not working
rrm74001
Member #9,548
February 2008

I am trying to simply have the program pause for 1 second between executing each blit(); function, as shown below. However, I keep getting build errors, saying sleep(); is undefined, even though I am including the windows.h header file? Any ideas why this is not working?

Thank you in advance for your response.

1#include <allegro.h> // You must include the Allegro Header file
2#include <windows.h> //Include this for the sleep functions
3 
4int main(int argc, char *argv[])
5{
6 allegro_init(); // Initialize Allegro
7 install_keyboard(); // Initialize keyboard routines
8 set_color_depth(16); // Set the color depth
9 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800,600,0,0); // Change our graphics mode to 800x600
10 BITMAP *bitmap001 = NULL; //Declare a BITMAP called bitmap001
11 bitmap001 = load_bitmap("GFX/image001.bmp", NULL); // Load our picture
12 blit(bitmap001, screen, 0,0,SCREEN_W/2-50,SCREEN_H/2-55,50,55); // Draw from 0,0 to 50,55 on the screen at (SCREEN_W/2-50,SCREEN_H/2-55)
13 sleep(1000);
14 blit(bitmap001, screen, 50,0,SCREEN_W/2,SCREEN_H/2-55,100,55); // Draw from 50,0 to 100,55 on the screen at (SCREEN_W/2,SCREEN_H/2-55)
15 sleep(1000);
16 blit(bitmap001, screen, 0,55,SCREEN_W/2-50,SCREEN_H/2,50,110); // Draw from 0,55 to 50,110 on the screen at (SCREEN_W/2-50,SCREEN_H/2)
17 sleep(1000);
18 blit(bitmap001, screen, 50,55,SCREEN_W/2,SCREEN_H/2,100,110); // Draw from 50,55 to 100,110 on the screen at (SCREEN_W/2,SCREEN_H/2)
19 readkey();// Wait untill a key is pressed
20 destroy_bitmap(bitmap001); //Release the bitmap data
21 return 0; // Exit with no errors
22}
23END_OF_MAIN() // This must be called right after the closing bracket of your MAIN function.
24 // It is Allegro specific.

Trent Gamblin
Member #261
April 2000
avatar

The function is called "Sleep" with a capital 'S'. Besides that, you should include winalleg.h instead of windows.h (just replace the second include with winalleg.h). It has to do some magic since Allegro and the Windows API use some of the same structure names.

gnolam
Member #2,030
March 2002
avatar

Or just use rest() :P

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

rrm74001
Member #9,548
February 2008

Quote:

The function is called "Sleep" with a capital 'S'. Besides that, you should include winalleg.h instead of windows.h (just replace the second include with winalleg.h). It has to do some magic since Allegro and the Windows API use some of the same structure names.

AH HA! After I posted this, I found out it was Sleep(); (With a capital S), but it still did not work. But that winalleg.h header file worked like a charm. I remember using windows.h header file to do this same thing before, I guess I was just lucky that time.

Thanks for your help. By the way, is there some repository that list all of the header files that are associated with Allegro? The hardest thing I find with programming is figuring out what header files do what.

gnolam
Member #2,030
March 2002
avatar

allegro.h is the only one you should need. If you're using platform-specific headers, chances are you're doing something wrong. Like using Sleep() here instead of rest(). :P

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

rrm74001
Member #9,548
February 2008

Quote:

allegro.h is the only one you should need. If you're using platform-specific headers, chances are you're doing something wrong. Like using Sleep() here instead of rest(). :P

Oh I see. I guess the Manual would be helpful in the case, huh? I am going to try and compile this on my Mac using the rest(); function. Thanks again everyone for your help.

Go to: