pretty simple, create two variables. One named tmin and one named tsec. We will use these variable to display time with:
- Code: Select all
int tmin,tsec;
sprintf(text,"%d:%d",tmin,tsec);
sprintf allows us to use formatting when displaying a string, including variables.
but how to display the seconds and minutes?
by using the code I've already provided you, you can easily display the minutes.
And by using the modulus operator %, you can display the seconds too!
- Code: Select all
int tmin,tsec;
tmin=(float)frame/1800;//1800=30*60, 30 being the fps
tsec=(int)((float)frame/30)%60;//30 being the fps
sprintf(text, "%d:%02d",tmin,tsec);
%d will display integers normally
%02d will display integers while always filling with 2 0's if there's not enough digits.
the 0 means the filling kind, 2 means how many zeros it should be filled with.
http://www.cplusplus.com/reference/clib ... o/sprintf/what (float) does is convert a variable into a float, so when you perform an operation (In this case divide by 1800), you will have more precision. Because in theory, if you divide an integer directly, there will be less precision than if you divide it as a float and then convert it into an integer.
in tsec, you can see we are using (int) because % cannot use any other form of type. % gives you the remainder of a division, but I prefer to think of it as a sort of warping function.