Re: Timing issue



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

.



Relevant Pages

  • Re: Fade into a Picture Box or Image Control
    ... Joe users old P3 only manages to draw a couple of frames a second and the same animation takes forever. ... Dim StartTime As Long, EndTime As Long, TimeNow As Long ... Where DrawFrame() draw the frame at the given opacity, I prefer doing this rather than cluttering the animation loop ...
    (microsoft.public.vb.winapi.graphics)
  • Re: Sagnac Threads United
    ... I've made minor internal changes to my animation. ... My animation is NOW for a large rotating ring. ... nature of those 'apparent' motions in YOUR ROTATING frame. ...
    (sci.physics.relativity)
  • Re: How do I generate an animated pdf file from xfig/metapost
    ... I will post the source code below for an animation that ... I've done which illustrates how an ellipse is constructed. ... This PDF will have each frame of the ... Draw the ellipse dashed ...
    (comp.text.tex)
  • Re: Timing issue
    ... fartin' in the wind here but I do know that in a GUI setting you have to ... 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 ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: Flashing a sprite
    ... you've reached the end of the animation, in which case frameIndex would go ... I guess the 2 would be my amount of seconds....but after gametime ... frames display frame 0, x amount of frames display frame 1" etc... ... you could just make a 2-frame animation for your flashing sprite. ...
    (microsoft.public.win32.programmer.directx.managed)