简体   繁体   English

Cocos2d,iOS 7.1:CCLabelTTF隐藏了ccDrawLine

[英]Cocos2d, iOS 7.1: CCLabelTTF hides ccDrawLine

I'm trying to use a CCLabelTTF in the upper part of the screen, while drawing a line in the lower part using ccDrawLine. 我正在尝试在屏幕上方使用CCLabelTTF,而在下方使用ccDrawLine绘制一条线。 When the app starts, the label is empty, and after a while it's updated with some text. 应用启动时,标签为空,并在一段时间后使用一些文本进行更新。 The line is drawn constantly in the draw method like that: 像这样在draw方法中不断画线:

- (void)draw {

    ccDrawColor4B(0, 255, 0, 0);
    glLineWidth(40.0f);
    ccDrawLine(ccp(0, 0), ccp(200, 200)); 
}

Thing is, the second the label is updated with text and actually displays something, the line disappears and is not drawn again, even if the label goes empty again. 问题是,第二次使用文本更新标签并实际显示内容,即使标签再次变空,该行也会消失并且不会再次绘制。 I'm not using any background at the moment, so it's not hiding it. 我目前没有使用任何背景,因此没有隐藏它。 I tried playing around with zOrders (even though the label and the line are in different areas of the screen) and still the line disappears. 我尝试使用zOrders(即使标签和该行位于屏幕的不同区域中),该行仍然消失。 I even tried creating a CCSprite subclass with only an init and a draw method, and using it to draw the line. 我什至尝试仅使用init和draw方法创建CCSprite子类,然后使用它来画线。 Here's what I have in this class: 这是我这堂课的内容:

@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

And here's what I add to my main layer: 这是我添加到主层的内容:

_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];

What am I missing? 我想念什么?

I think you should add 我认为你应该补充

[super draw];

att the begiining of your draw method when you override the draw method of CCSprite. 当您重写CCSprite的draw方法时,请尝试执行draw方法的开始。 Only then a subclassed CCSprite does “sprite rendering” for its overridden method. 只有这样,子类CCSprite才对其覆盖的方法进行“ Sprite渲染”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM