gpt4 book ai didi

c++ - Cocos2d-x 中的文本环绕

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:24:06 25 4
gpt4 key购买 nike

我试图让我的文本标签在文本比它们所在的框长时自动调整大小。我还希望它支持多行功能。我在网上做了一些搜索,发现它曾经是这样工作的:

CCLabelTTF::labelWithString(“This is a sentence longer than a line width.2d-x”, CGSizeMake(**0, 0**), UITextAlignmentCenter, “Thonburi”, 20);

但这似乎在 cocos 中不再可用,所以我不知道该怎么做。现在我的标签设置如下:

myQuestion = Label::createWithTTF("Testing to see if text wrap will work" ,c_strFontNameBase, 50);
myQuestion->setPosition(boxLabel->getContentSize().width/2, boxLabel->getContentSize().height/2);
boxLabel->addChild(myQuestion, 50);

有没有什么方法可以让我使用与上面示例类似的方法来使我的工作正常进行?这似乎不是一件很难做的事情,但我发现在线缺乏相关文档...

最佳答案

我相信,您只能使标签的一个维度自动调整大小,即宽度或高度都可以自动调整大小。默认情况下,当您按如下方式创建标签时,标签的宽度会设置为使用固定高度自动调整大小:

auto label = Label::createWithTTF("Hello World gsdhsgdh gshdghsg yutywe gdgshdgy bnbjh hshhashgy hjnbdnsdhh ghhsgdhg ghghghsd ghhghsd ghghghgsd jkjkhsdjkj ououisdusydsi kkjkxncmxcjh kcxhjxhcjx jkuiushjxchxjch hjhjchxuyuychjc ", "fonts/Marker Felt.ttf", 24);
// position the label on the center of the screen
label->setPosition(Vec2(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - label->getContentSize().height));

// add the label as a child to this layer
this->addChild(label, 1);

但是如果你想要多行支持,即固定宽度和可调整大小的高度,你只需要将标签的尺寸设置为固定宽度和零高度:

label->setDimensions(300, 0);

希望对您有所帮助。

关于c++ - Cocos2d-x 中的文本环绕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28992823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com