Displaying game Score

Started by
4 comments, last by Turt99 20 years, 11 months ago
if you had a score stored as an integer and you had images for each of the numbers, how would you display it? would you convert it to a string, then step through the array and convert each character back to an integer to represent a item in an array that would be used to display the correct number? the way I see it I''d have an array that would hold some information that I''d use to blit the number to the screen I''d use sprintf() to convert to a string and then I''d move through the string and use each number as the array index.. How would I know how long the string that I got from sprintf was? and does this sound like a good way to approach this? Please visit Turt99 Productions
FOLLOW ME ON TWITTER OR MY BLOG
Advertisement
If the score can be multiple digits, then you should probably treat the score as you would treat text. If you have a pictures of all the letters and characters you wish to display, put a handle to each of them in an array and paint them one after another.

e.g. You intend to print all the letters, capital and lower case, numbers and various punctuation.

Enumerate them in an enum:

enum CHARACTERS
{
TURT99_A, =0
TURT99_B,
...
TURT99_COMMA,
NUM_CHARACTERS
};

texture_handle text_texture_handles[NUM_CHARACTERS];

then, for each text item, loop over each character and draw it.

if('A')blahblah[TURT99_A];

[edited by - flangazor on May 1, 2003 12:05:36 PM]
I think you just explained the part that I already knew how I was going to do it...

the score will have to be initally stored as an integer so that I can add to it, and then you say I would make it a string, so I got that part with the sprintf()

But once I have a string of the score how can I tell how long it is? I see what you saying with the enum, it would allow me to display text messages as well (which is actually a good thing) I''ll probably make a simple little Font Engine to cover this actually so I can output the messages I''d like..

however, once again I''d like to know given a char array how would I tell where the text is?

Please visit Turt99 Productions
FOLLOW ME ON TWITTER OR MY BLOG
I figured this would be done all the time... I guess I can figure most of it out I''m just looking to say.. if I send in a char array how do I know when my text has stopped..



Please visit Turt99 Productions
FOLLOW ME ON TWITTER OR MY BLOG
normal c strings are null terminated, meaning there''s a character 0 at the end. When you sprintf(), it tacks it on there for you. This is how functions like strlen() (hint, hint) work.
Thanks thats what I needed, I what thinking that it wouldn''t have a termination... thats exactly what I needed...

*Runs off to do some coding*

Please visit Turt99 Productions
FOLLOW ME ON TWITTER OR MY BLOG

This topic is closed to new replies.

Advertisement