Page 3 of 3

Posted: Sun Dec 05, 2010 11:24 am
by DonKarnage
GetTime(), to my knowledge, will return system time in milliseconds.

Code: Select all

void AnimatedImage::Evaluate()
{
    float time = GetTime()->GetValue();

    int count = m_psurfaces.GetCount();
    m_index = (int)(time * count) % count;

    Image::Evaluate();
}
From the looks of it, m_index is used with m_psurfaces to choose the right image.
Time multiplied by number of images, then with the % (Modulo) the remainder of (time*count)/count

I never was good at math, maybe you can make sense of what that actually does... I'm gonna sleep on it, it's late :wacko:

Posted: Sun Dec 05, 2010 10:55 pm
by madpeople
Well, m_index always needs to be a value from 0 to count. modulo is an easy way to make the value wrap around.

if I had
m_index = i % count

and count = 4, then
i,m_index
0,0
1,1
2,2
3,3
4,0
5,1
6,2
7,3
8,0
...
See, m_index is always from 0 to count.

I'm not sure GetTime()->GetValue() does return millisecond time - they feel the need to multiply by count, and it is a float, where as a millisecond time is usually a long int. Perhaps it's seconds with a number of decimal places? You probably want to look up what it actually does if you want to understand this piece of code.