Sign in to follow this  
  • entries
    55
  • comments
    55
  • views
    24447

Confusion

Sign in to follow this  

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

Thanks for reading
-AEdmonds
Sign in to follow this  


2 Comments


Recommended Comments

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.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now