Sign in to follow this  

Title screen pause

This topic is 4599 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a title screen for my game that I want to display for a few seconds and then go on. What is a good way to do this. Keep in mind this is a console application, I am currently using system("pause"), which does the job, but the user has to hit a key to continue. The only thing I can think of is to just use a loop and kill time, is there a more elegant solution to this.

Share this post


Link to post
Share on other sites
Included in the Windows.h header is the sleep() function, which takes in its argument the minimum number of milliseconds to pause the thread.

EDIT: Too fast for me. :)

Share this post


Link to post
Share on other sites
You can also make your own delay function using <ctime> (or <time.h> in C).

#include <ctime>

void delay( long int milliseconds )
{
time_t current = clock();
time_t end = current + milliseconds;

for ( ; current <= end; )
current = clock();
}

// another way - they are basically the same
/* void delay( long int milliseconds )
{
time_t end = clock() + milliseconds;

while ( 1 )
if ( clock() == end )
break;
}
*/


int main()
{
delay( 4000 );
return 0;
}






Edit: You will probably never want a delay anywhere near the extent of a long int, so you can just use a regular int.

Edit: I just read that the resolution of clock() is 1 second, so the use of "milliseconds" is unnecessary. Maybe change it to seconds, but it makes no difference in the functionality.

Edit: Unless what I read proves to be false.

[Edited by - skulldrudgery on May 15, 2005 5:45:13 PM]

Share this post


Link to post
Share on other sites

This topic is 4599 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this