Monday, May 24, 2010

How to make animation in Borland C++??

I'm planning to make an animation of ascii images in c++..


But I have difficulity how to type the code in order for the program to play the sequence images.


I would like to use the clrscr(); method, but the problem is, the time between 2 frames is very short.





For instance, based on the code below:





--------------------------------------...


#include%26lt;iostream%26gt;


#include%26lt;conio%26gt;





int main()


{


cout%26lt;%26lt;"hi";


clrscr();


cout%26lt;%26lt;"hi";


cout%26lt;%26lt;"\nhi";








getche();


return 0;


}


______________________________________...





referring to the source code, the only words that can be seen is cout%26lt;%26lt;"hi";


cout%26lt;%26lt;"\nhi";





while the first hi can't be seen..





What is the best way to use clrscr(); to make animation??





Thank you..

How to make animation in Borland C++??
Use a sleep() function to stop the screen for a few seconds.


You may use as:


#include%26lt;iostream%26gt;


#include%26lt;conio%26gt;





int main()


{


cout%26lt;%26lt;"hi";





sleep(5);





clrscr();


cout%26lt;%26lt;"hi";


cout%26lt;%26lt;"\nhi";








getche();


return 0;


}


The sleep function suspends the work for a few seconds supplied as parameter.


The other function is delay() that makes similar task but in milliseconds.





So do not delay to test and try it.


With best wishes!
Reply:Put in a delay loop. This can be done similar to the following.





counter = 0;


do


{clrscr();


counter++;}


while counter %26lt;= 10;





You can play around with different numbers until the amount of blankness seems right. You can also use a delay loop like this with the cout statements to lengthen their stay on the screen.


No comments:

Post a Comment