我有一个使用 SDL_ttf 来显示文本的小应用程序。这通过以下方式工作得很好: TTF_RenderText_Solid( font, "text here", textColor );
但是,我想知道如何渲染整数。我假设他们需要先转换为字符串,但我遇到了这个问题。特别是当我想像这样显示鼠标的 x 和 y 位置时:
if( event.type == SDL_MOUSEMOTION )
{
mouse_move = TTF_RenderText_Solid( font, "need mouse x and y here", textColor );
}
我相信我可以通过 event.motion.x
和 event.motion.y
获取 x 和 y 坐标。这是正确的吗?
最佳答案
I am assuming they would need to be casted to strings first
不,不是类型转换而是转换。最简单的方法是使用流,例如:
#include <sstream>
// ...
std::stringstream text;
// format
text << "mouse coords: " << event.motion.x << " " << event.motion.y;
// and display
TTF_RenderText_Solid(font, text.c_str(), textColor);
关于C++/SDL 渲染文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7417882/