Sign in to follow this  

Unity How do I make and use a timer correctly?

This topic is 2325 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

Hello, I am currently working on a Pacman remake (purely 2D, my first game btw so its more a try to learn some program skills than to create something fun).
So now I am having the problem that the game runs with different speed on different computers and since I have read that there are different timers out there I would like to know what are the best ones (I am programming under Windows but I would like to have the opportunity to easily port the game to Linux or even portable devices).

But I also need help with the principle of a timer. I know it measures (or returns) the time that has passed since the last call (or do only certain timers do that?) but what do I have to do with that information now?


For my game I would like to have a constant game speed of 60fps so I think I know what I have to do with a PC that is too fast - after he is done with the update, drawing etc functions of the game, he has to wait a certain time (what would that be if I want 60fps?) until he repeats them so I simply put him on wait until that time has passed.

But what do I have to do with a PC that is not so fast? For example a really slow PC that makes only 10 fps (or more drastically 0.1fps), what is that PC supposed to do to keep up with the game speed?

Thanks in advance :)

Share this post


Link to post
Share on other sites
Hello

I give you my class that implements a timer :

[code]
class Chrono
{
protected:
double t;

double getTime()
{
__int64 count,freq;
QueryPerformanceCounter((LARGE_INTEGER *)&count);
QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
return double(count)/double(freq);
}

public:
Chrono(void)
{
reset();
}

void reset(double time=0.0)
{
t=getTime()-time;
}

double time()
{
return getTime()-t;
}

~Chrono(void)
{}
};
[/code]

(I can explain it if that's not clear)
Hope that helps you
:wink:

Share this post


Link to post
Share on other sites

This topic is 2325 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.

Guest
This topic is now closed to further replies.
Sign in to follow this