Game Development Reference
In-Depth Information
{
m_digits.push_back(n % 10);
n /= 10;
}
m_digits.push_back(n);
}
wchar_t operator()(unsigned int position) {
if ( m_number >= pow(10, position) )
{
return L'0' + m_digits[m_digits.size() - 1 - position];
}
return 0;
}
private:
int m_number;
std::vector<int> m_digits;
}
We store the number as an int to allow us to perform a validation when we try to retrieve
thedigitataspecifiedposition,aslongasthenumberisgreaterthanorequalthan
then there is a digit for that position, otherwise, we return zero to indicate that there is no
digit at that position.
Figure 60 - Extracting single digits from a number allows us to draw them independently.
Having extracted the digits from a given number, we can use as indices to look up for the
appropriate glyph in a font. Alternatively, this also opens the door to creating sprite-based
numbers, we create an array of sprites from 0 to 9, then use the digit to look up the sprite
we should use, giving us the ability of displaying animated digits.
Search WWH ::




Custom Search