gpt4 book ai didi

ios - Cocos2d,iOS 7.1 : CCLabelTTF hides ccDrawLine

转载 作者:行者123 更新时间:2023-11-29 03:02:32 24 4
gpt4 key购买 nike

我尝试在屏幕的上半部分使用 CCLabelTTF,而在下半部分使用 ccDrawLine 绘制一条线。当应用程序启动时,标签是空的,过了一会儿它更新了一些文本。这条线在 draw 方法中不断地被画成这样:

- (void)draw {

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

事情是,当标签用文本更新并实际显示某些内容时,线条就会消失并且不会再次绘制,即使标签再次变为空也是如此。我目前没有使用任何背景,所以它没有隐藏它。我尝试使用 zOrders(即使标签和线条位于屏幕的不同区域),但线条仍然消失了。我什至尝试创建一个只有 init 和 draw 方法的 CCSprite 子类,并用它来绘制线条。以下是我在本类(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

这是我添加到主层的内容:

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

我错过了什么?

最佳答案

我认为你应该添加

[super draw];

当您重写 CCSprite 的绘图方法时,请注意您的绘图方法的开始。只有这样,子类化的 CCSprite 才为其覆盖的方法进行“ Sprite 渲染”。

关于ios - Cocos2d,iOS 7.1 : CCLabelTTF hides ccDrawLine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23151435/

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