我想旋转一个CCLabelTTF围绕它的中心。
但看起来不像。它看起来更像是CCLabelTTF底部的旋转。
代码:
CCLabelTTF *aLabel ... init/addChild and so on
CCRotateBy *rotateLabelA = [[CCRotateBy alloc] initWithDuration:0.5f angle:-60.0f];
aLabel.string = @"0";
aLabel.anchorPoint = ccp(0.5f, 0.5f);
[aLabel runAction:rotateLabelA];如果字母是CCLabelTTF,如何围绕其可见中心旋转?
我能够使CCLabelTTF的边界框可见:

如图中所示,包围框要大得多。但是没有一个公式来决定信的中间位置。
发布于 2013-09-08 12:57:12
我找到了如何找到CCLabelTTF的中间点。
float fontSize = bLabel.fontSize; // actual Font size in pixels
float labelHeight = bLabel.contentSize.height; // actual label height ( the same as boundingBox.size.height )
float offset = labelHeight - fontSize; // the free room under the font
float halfFontSize = fontSize / 2;
float percentMiddleOfFont = (halfFontSize + offset) / labelHeight;
bLabel.anchorPoint = ccp(0.5f, percentMiddleOfFont);发布于 2013-09-07 19:13:46
如果将anchorPoint = cpp(0.5f,0.5f)设置为某个ccNode对象,它将围绕其中心旋转,这是使用boundingBox属性计算的。
问题是标签的boundingBox.size.height与实际高度不同。这就是为什么它不是围绕着中心旋转的。
我不确定在这样一个手动解决方案,但它对我有一天。
CCLabelTTF *label = [CCLabelTTF labelWithString:@"0" fontName:@"Marker Felt"fontSize:24];
label.position = ccp(winSize.width /2.0f, winSize.height / 2.0f);
float fontSize = label.fontSize; // actual Font size
float labelHeight = label.contentSize.height; // actual label height ( the same as boundingBox.size.height
float offset = (labelHeight - fontSize - (labelHeight - fontSize) / 2.0f) / labelHeight / 2.0f;
label.anchorPoint = ccp(0.5f, 0.5f + offset);
[layer addChild:label];
[label runAction:[CCRotateBy actionWithDuration:10.0f angle:-360]];https://stackoverflow.com/questions/18676402
复制相似问题