SDL_ttf 和数字 (int)
int score = 0;
char* fixedscore=(char*)score;
.
.
.
imgTxt = TTF_RenderText_Solid( font, fixedscore, fColor );
^^ 这不起作用 - 看起来固定分数为空或不存在。
int score = 0;
char* fixedscore=(char*)score;
.
.
.
imgTxt = TTF_RenderText_Solid( font, "Works fine", fColor );
^^ 工作正常,但是...
我猜将 int 转换为 char* 不会真的不起作用。那么如何在 SDL 中打印乐谱呢? 哦,还有一件事:为什么文字这么难看?
int score = 0;
char* fixedscore=(char*)score;
.
.
.
imgTxt = TTF_RenderText_Solid( font, fixedscore, fColor );
^^ This doesn't work - looks like fixedscore is empty or doesn't exists.
int score = 0;
char* fixedscore=(char*)score;
.
.
.
imgTxt = TTF_RenderText_Solid( font, "Works fine", fColor );
^^ Works fine, but...
I guess converting int to char* doesn't really work. So how do you print scores in SDL?
Oh and one more thing: why is the text so ugly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了类似的问题,
我有
I faced a similar problem,
I had
选角不是你想要的。此代码:
相当于执行以下操作:
我假设您正在尝试让
fixedscore
来保存分数中数字的文本值。仅使用标准 C++ 的最简单方法是通过 stringstream:Casting is not what you want. This code:
is the equivalent of doing:
I assume you are trying to get
fixedscore
to hold the textual value of the number in score. The easiest way using just standard C++ is viastringstream
: