我尝试添加一个图层,其目的是用白色填充整个场景。
我尝试这样做,如下所示:
// Inside a cass which extends CCScene
- (id)init {
if (self = [super init]) {
// Create the flash layer on level restart
_flashLayer = [[CCLayerColor alloc] init];
[_flashLayer setColor:ccc3(255, 255, 255)];
[self addChild:_flashLayer z:0];
[_flashLayer release];
}
return self;
}
问题是,无论如何设置图层的颜色,我都会出现黑屏。
另一件事,如果我尝试如下创建图层:
_flashLayer = [[CCLayerColor alloc] initWithColor:ccc4(255, 255, 255, 255)];
我收到以下错误:
Incompatible type for argument 1 of 'initWithColor:'
我查看了源代码,一切似乎都符合预期。
任何人都可以阐明这个问题吗?
谢谢。
最佳答案
您有两种选择:
_flashLayer = [[CCLayerColor layerWithColor:ccc4(255, 255, 255, 255)];
[self addChild:_flashLayer z:0];
要么
// the key is to add (CCLayerColor *) to cast
// or you will meet 'incompatible type for argument' error at compile time
_flashLayer = [(CCLayerColor *)[CCLayerColor alloc] initWithColor:ccc4(255, 255, 255, 255)];
[self addChild:_flashLayer z:0];
[_flashLayer release];
关于iphone - CCLayerColor无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10257499/