Jump to content
  • Advertisement
Sign in to follow this  
kelcharge

Slow it down.

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

I had trouble with my pong game being to fast on some computers. I was wondering how I would make it the same speed on each computer?

Share this post


Link to post
Share on other sites
Advertisement
use timeGetTime to calculate the time between each frame and divide by 1000
then multiply that number to the speed of the objects

Share this post


Link to post
Share on other sites
To clarify:
instead of something like:

void Update()
{
int SpeedX = 5;
int SpeedY = 3;
Ball.x += SpeedX;
Ball.y += SpeedY;
}

do this:

void Update()
{
static DWORD LastTime = timeGetTime();
float DeltaTime = (timeGetTime() - LastTime) / 1000.0f;

Ball.x += (int)(SpeedX * DeltaTime + 0.5f); //Adding 0.5f and casting to an int effectively rounds
Ball.y += (int)(SpeedY * DeltaTime + 0.5f);
LastTime = TimeGetTime();
}

You'll probably have to drastically increase your speed to get the desired result, so try using something like the above and then adjusting your speeds until you're happy with them.

Also make sure you link to winmm.lib, either through VC++ properites or by adding the line #pragma comment(lib, "winmm.lib") to your main source file.

Share this post


Link to post
Share on other sites
To expand on what mike25025 was saying, the common approach is to make your movement time-based, instead of frame-based. All your objects should have a direction and speed (miles per hour, units per second, etc.) variable. Depending on your implementation, you may want to google for "3d vector math" - (I would anyway, since it will make things alot easier). Here's some pseudo-code:


.) main loop
.) get elapsed time since last frame
.) move your objects by speed*time
.) draw your objects


Hope this helps - good luck!

EDIT: ms291052 - you're too quick for my fingers! :)

Share this post


Link to post
Share on other sites
there should be no need to round or cast
the ball positions should be stored as floats
then when rendering the will be casted into ints

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The best way is to have a constant update frequency.
This way there is never any difference between two computers updating over the same period.

With a changing time difference the end results may differ.
A good example is that of Quake 3 and rocket jumping. Certain framerates would yield better results than others due to different time differences.

Share this post


Link to post
Share on other sites
ap there are problems with using a constant update frequency
on fast computers it will look bad
and slow computers might be to slow to reach the frequency makeing the game very slow

using a time delta it will work well on all computers

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!