Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Race car game, car moving faster on faster computer

I understand why it does that but I don't really have any idea of how to prevent that. So the scenario is, every frame I move the car by a certain of predefined pixels. What happens is when I go on slow or faster computer... well I get less or more frames per seconds so the car moves either slower or faster. I was wondering how I could prevent that.

I suspect that I would have the same problem using any library... This is my first time doing real time stuff like that.

like image 388
DogDog Avatar asked Feb 04 '10 16:02

DogDog


People also ask

How do I make my racing game feel faster?

So, if you feel that your car isn't going fast in your racing game, then maybe all you need to do is tweak some settings, get a bigger monitor, and use your gaming headset. With that, you get a better driving experience, all in the safety of your room.

What is Type rush?

"TypeRush is a really fun typing game for kids where players are given a series of sentences to copy. The more quickly and accurately you type, the faster you propel your car or boat through the race.


2 Answers

I suspect your current code looks somehow like this

 // to be called every frame
 void OnEveryFrame()
 {
     MoveCar();
     DrawCarToScreen();
 }

But it should be like this:

 // to be called - for example - 50 times per second:
 void OnEveryTimerEvent()
 {
     MoveCar();
 }

 // to be called every frame
 void OnEveryFrame()
 {
     LockTimerEvents();
     DrawCarToScreen();
     UnlockAndProcessOutstandingTimerEvents();
 }

You have to set up an according timer event, of course.

like image 188
Doc Brown Avatar answered Dec 24 '22 12:12

Doc Brown


Move car according to timers and not framerate. i.e. Car model should be independent of the display representation.

like image 40
Artyom Avatar answered Dec 24 '22 10:12

Artyom