• entries
55
55
• views
24519

# Confusion

119 views

I haven't done much today. Been distracted with xbox live [rolleyes]. I managed to get lives easily added but the score is giving me a bit of hassle.

Let's see if I can sort it out by writing my thoughts. Ok, I have the player's score stored as an int (actually that might be the problem - I may need a larger data type). And in the render function I am trying to get each digit separatly so I know what to print. At the moment I have a for loop that divides the player's score by 10^i to give the digit needed. Nope, that didn't help at all. I am clearly confused by the whole thing. I'll sleep on it and give it another go tomorrow.

-AEdmonds

Personally, I wouldn't use maths to convert your int into separate digits. You can do it that way, but I find this easier:

void DrawScore(int Score,float AtX,float AtY)
{
std::ostringstream Os;
Os << Score;

std::string S=Os.str();
while(S.length()<9) S="0"+S; // to left-pad zeros

float X=AtX;
for(size_t I=0;I<S.length();++I)
{
RenderCharacter(X,AtY,S[I]);
X+=WidthOf(S[I]);
}
}


RenderCharacter(X,Y,Char) and WidthOf(Char) are just dummy functions whose implementation depends on how you are rendering text.

Otherwise I'm just converting the number to a string then iterating through it character by character. Performance hit is negligible on a modern PC and of course you could always cache the string and only change it when the score changed.

Ah, that's a good way of doing it. I'll try doing that. Thanks.