gpt4 book ai didi

ios - cocos2dV3.0中如何截断标签

转载 作者:行者123 更新时间:2023-11-29 02:55:09 25 4
gpt4 key购买 nike

我试图在文本变大时截断标签,但它却从中心移动到左侧。

这是我的片段。

 CCLabelTTF *playerLabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"Playerdadsadsd %d",i+1] fontName:@"Helvetica-Bold" fontSize:fontSize];

playerLabel.color = playerColor;
playerLabel.name = [NSString stringWithFormat:@"%d",1002+i];
playerLabel.position = ccp(playerSprite.position.x + playerSprite.contentSize.width + 10, yPos);
playerLabel.adjustsFontSizeToFit = YES;
[self addChild:playerLabel];

enter image description here

最佳答案

我不确定你想达到什么目的,但尝试将 dimensions 参数传递给 init 方法:

//The label won't go out of this rectangle
CGSize rect = CGSizeMake(viewSize.width * 0.1f, viewSize.height * 0.1f);

NSString *text = [NSString stringWithFormat:@"Playerdadsadsd %d",i+1];
CCLabelTTF *playerLabel = [CCLabelTTF labelWithString: text
fontName: @"Helvetica-Bold"
fontSize: fontSize
dimensions: rect]; // <-- Note this parameter

//.. the rest of your code..

关于ios - cocos2dV3.0中如何截断标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23994643/

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