Re: Timing issue
- From: "Robert Dunlop [MS MVP]" <rdunlop@xxxxxxxx>
- Date: Tue, 8 Aug 2006 06:55:19 -0700
"Daniel" <DanielV@xxxxxxxxxxxxxxxx> wrote in message news:uF0866huGHA.4952@xxxxxxxxxxxxxxxxxxxxxxx
Hey guys
I was advised that the best animation method is to update the animation on a time basis rather than frame basis, which i agree with so that even on varying procesor speds the animation will remain consistent.
ZMan pointed me to this formula:
if( _gameTime.Seconds/x % 2 > 0 )
//then next frame
The idea being that you set x to however many seconds you want your next frame to kick in on. So ever second set it to 1, every 2 seconds set it to 2 etc.
However Z said that this will also work for half seconds but i am finding it doesnt? How can i use a similar equation so that i can move to my next frame in the animation every 0.5 seconds?
Z have i done something wrong here? If i set x to 0.5f my anim gets stuck. (e.g. never results in 1)
That statement will never result in a value other than zero, if you set x to 0.5f, because TimeSpan.Seconds is an integer. Divide it by 0.5, you will get a multiple of two, so seconds/0.5 % 2 will always equal zero! Since you are dealing with an integer value in seconds, this modulus operation will provide aliased results for any non-integer values of x.
I'm not clear on the intent of this equation, or if it's doing what you really want, but you could get the same functionality at non-integer intervals and intervals below one second by doing this:
if (_gameTime.TotalSeconds/x%2.0>=1.0) ...
TotalSeconds returns the total number of seconds as a double, while Seconds returns an integer that represents the seconds portion of the timespan if it were expressed as hh:mm:ss. Thus it will only range from 0 to 59 (or -59 for negative timespans). This also means that any value of x that does not divide into 60 evenly would cause an uneven interval once a minute using an integer modulus.
--
Robert Dunlop
Microsoft DirectX MVP
http://rdunlop.spaces.msn.com/
-------------
The X-Zone
http://www.directxzone.com/
-------------
The opinions expressed in this message are my own personal views and do not reflect the official views of the Microsoft Corporation.
The MVP program does not constitute employment or contractual obligation with Microsoft.
.
- Follow-Ups:
- Re: Timing issue
- From: Daniel
- Re: Timing issue
- References:
- Timing issue
- From: Daniel
- Timing issue
- Prev by Date: Re: flexing an 3D object
- Next by Date: Re: Timing issue
- Previous by thread: Re: Timing issue
- Next by thread: Re: Timing issue
- Index(es):
Relevant Pages
|