以自定义字体打印变量值 [英] Printing a variable value in a custom font

查看:82
本文介绍了以自定义字体打印变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用SDL制作游戏,我制作了自己的自定义字体,现在,例如,如果我想打印分数变量,我就不必检查变量值是什么样的: br/>

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"是一个类,"show_text"是将文本打印到屏幕上的成员)



("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?

推荐答案

不要混淆:变量,其值和字符串表示形式.
您不打印变量",而您也不打印"任何东西!

即使"font.show_text" API存在,我也不会使用这样的API,因为它是错误的抽象.

您的答案取决于您使用的UI库(始终使用标签:WPF,WinForm或其他?).
当您说"SDL"时,应解释您暗示的可能含义,以免歧义.请参见: http://en.wikipedia .org/wiki/SDL [ ^ ]:- ).

通常,您使用FrameworkElement中的Control(仅WPF)在UI中显示字符串.它们都具有属性Font.就这么简单.

—SA
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


这篇关于以自定义字体打印变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆