Moving an object according to time

Started by
1 comment, last by moucard 20 years ago
Hi all, my problem is I create a small ball on the screen and I need to move that ball according to some timed event. For example when 5 seconds pass I would like the ball to make a full circle from its current position and the time to do the circle last 0.5 seconds. Right now I can catch the event of when the 5 seconds have passed. But how can I move the ball according to a timer so the full circle is performed in 0.5 seconds? Thanks in advance.
Advertisement
If you setup your timer so you know the interval that has passed between two frames then you can use a preset "velocity" value to calculate the amount to move based upon the amount of time which has passed. Your velocity value will be the number of pixels to move each second so the equation to use to find out how much to move by each frame will be:

movement = velocity/(1/secs per frame)

You can simply plug the second part of this directly into your movement code so ballPos += (velocity/(1/FrameTime));
is that the same as
movement = velocity * secs per frame
?

This topic is closed to new replies.

Advertisement