Click here to Skip to main content
15,889,739 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I'm making a game in SDL and I made my own custom font, now if I for example want to print the score variable I don't want to have to check what the variables value is like this:

if ( Score == 0 )
    font.show_text( 0, 0, "Score: 0", screen );
if ( Score == 1 )
    font.show_text( 0, 0, "Score: 1", screen );


("font" is a class and "show_text" is a member that prints the text to the screen)
Is there a way to display the value maybe with the string class or anything else?
Posted
Updated 25-Oct-11 0:14am
v3
Comments
Richard MacCutchan 27-Mar-11 15:28pm    
Score.ToString()?
Richard MacCutchan 25-Oct-11 7:07am    
Do you have a supplementary question?

1 solution

Don't mix up: variable, its value and presentation of a string.
You don't "print a variable", you and don't "print" anything!

Even if "font.show_text" API existed I would not use such API as it's a wrong abstraction.

Your answer depends on the UI library you use (always use tags: WPF, WinForm, or what?).
When you say "SDL", you should explain what of the possible meanings do you imply, see for disambiguation: http://en.wikipedia.org/wiki/SDL[^] :-).

Typically, you use Control of FrameworkElement (WPF only) to present a string in the UI. They all have the property Font. As simple as that.

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900