2

当一串文本过去300时,我希望它下降到一个新行并继续。我读到这就是你的做法,但它不起作用 - 它只是延长了文本。

如何做到这一点?

const char* message = "example text to test that it drops to a new line."; 
std::string fontFile = "Font/font.ttf";
int fontSize = 16;

TTF_Font *font = nullptr;
    font = TTF_OpenFont(fontFile.c_str(), fontSize);

SDL_Color textColor = { 0, 300, 200 };
SDL_Surface *surf = TTF_RenderText_Blended_Wrapped(font, message, textColor, 300);
    texture = SDL_CreateTextureFromSurface(m_p_Renderer, surf);

int w,h;
TTF_SizeText(font,message,&w,&h);

srcRect.x = 0;
srcRect.y = 0;
destRect.x = 0;
destRect.y = 0;

srcRect.w =w;
srcRect.h = h;

destRect.w =w;
destRect.h = h;
4

1 回答 1

2

A 认为错误在于TTF_SizeText(...)调用。它不知道您设置的边界,也可能忽略端线。尝试删除该行并将其改为:

int w, h;
w = surf->w;
h = surf->h;

我希望它有所帮助。

于 2014-03-09T23:43:35.937 回答