Jump to content
• Advertisement
• entries
55
• comments
55
• views
24761

# Confusion

155 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

## 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
Ah, that's a good way of doing it. I'll try doing that. Thanks.

## 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
• Advertisement
• Advertisement

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!