Sign in to follow this  
kelcharge

Slow it down.

Recommended Posts

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this