#### Archived

This topic is now archived and is closed to further replies.

# Different speeds on different machines

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

## Recommended Posts

OK, so I have my basic DirectX application running which takes input from mouse and keyboard, and has the flipping mechanism in place. I''m starting to think about actual gameplay and animations and all other related stuff. One of the problems I have is timing the game. What I mean is, different machines will run at different rates? So, if I have an animation that I want to last 1 second, how do I moderate this so that it runs at the speed on different machines? Also, when moving objects across the screen, how do I make sure that they don''t whizz across on faster machines and crawl across on slower machines? I''m sure that I am missing something simple but I am indeed missing it. Thanks in advance for any pointers!

##### Share on other sites
What I did to fix this problem on my game was make a timer than give each character (including AI) a velocity . So when they moved I did not just move xPos & yPos I changed the velocity. Then evey 70,000 if a second I called a function called update
which added the velocity to the xPos. Which made the whole movement work to a timer. If you don''t know about a timer check MSDN 4:
Performance Counter. because a normal windows timer will not work in game ( not enough accuracy) & windows timer msg have low importance so often the msg is ignored by wndproc.
hope this helps WizHarD

##### Share on other sites
Great, thanks for the quick response Wiz!

I know about Windows timers, not good for speed reliant things like this. I''m using what I think it a fairly standard game loop where my code controls the message loop, rather than relying on the message loop to control my code

You say you give your objects a velocity, what would be an example of that; are we talking 50pix/sec or something like that?So then each frame you just add a proportion of the velocity based on how much of a second has passed! Excellent. You''ve just made it click for me, thanks!!

I''m not sure what you mean by "every 70,000 if a second I called a function called update"?

##### Share on other sites
Can''t you use TimeGetTime at both the start and end of the game loop, and pause at the end for the difference?

  Procedure GameLoop;var StartTime, EndTime: integer;begin // record the start time of the loop StartTime:=TimeGetTime; // insert game logic here // record the end time of the loop EndTime:=TimeGetTime; // if the difference is less than 10 mils, pause for the difference if StartTime-EndTime < 10 then Sleep(10-(StartTime-EndTime));end;

~ There''s no substitute for failure ~

##### Share on other sites
Thanks MarkyD, that''s the way I was going to do it but that means limiting everything to the lowest common denominator. Whereas using the velocity method lets each machine run at their own pace.

For instance, a machine that runs faster can move sprites a single pixel at a time and still get a good frame rate which will look much smoother.
Conversely a slower machine will run at the same speed but maybe move the sprites five pixels at a time producing a jerkier motion but running at the same speed.

I''ve now got it working quite nicely, and I built in acceleration as well for rocket powered weapons Now I just need some sprites to replace the rectangles I am drawing at the moment.

• 39
• 15
• 9
• 23
• 10