【发布时间】:2014-04-18 20:02:42
【问题描述】:
我正在尝试在屏幕的上部使用 CCLabelTTF,同时使用 ccDrawLine 在下部绘制一条线。当应用程序启动时,标签是空的,一段时间后它会更新一些文本。这条线在 draw 方法中不断绘制,如下所示:
- (void)draw {
ccDrawColor4B(0, 255, 0, 0);
glLineWidth(40.0f);
ccDrawLine(ccp(0, 0), ccp(200, 200));
}
问题是,当标签用文本更新并实际显示某些内容时,该线消失并且不再绘制,即使标签再次变空。我目前没有使用任何背景,所以它没有隐藏它。我尝试使用 zOrders(即使标签和线条位于屏幕的不同区域),但线条仍然消失。我什至尝试用一个 init 和一个 draw 方法创建一个 CCSprite 子类,并用它来画线。这是我在这门课上的内容:
@implementation DrawingSprite
- (id)init {
if (self = [super init]) {
}
return self;
}
- (void)draw {
ccDrawColor4B(0, 255, 0, 0); //Color of the line RGBA
glLineWidth(40.0f); //Stroke width of the line
ccDrawLine(ccp(0, 0), ccp(200, 200));
}
@end
这是我添加到主层的内容:
_topLabel = [CCLabelTTF labelWithString:@"" fontName:@"Helvetica" fontSize:24];
_topLabel.position = ccp(winSize.width/2, winSize.height - 100);
_topLabel.color = ccc3(255,255,255);
_topLabel.zOrder = -1;
[self addChild:_topLabel];
_drawingSprite = [DrawingSprite node];
_drawingSprite.zOrder = 10;
[self addChild:_drawingSprite];
我错过了什么?
【问题讨论】:
标签: ios objective-c cocos2d-iphone