我想淡化一个 CCLayerColor,这似乎很简单,但它只是不起作用......这是我所做的:
加载屏幕.h
@interface LoadingScreen : CCLayerColor{
}
-(id)init;
-(void)setOpacity:(GLubyte)opacity;
@end
加载屏幕.m
@implementation LoadingScreen
-(id)init{
if ((self=[super initWithColor:ccc4(66 , 66, 66, 255)])){
self.isTouchEnabled = NO;
}
return self;
}
-(void)setOpacity:(GLubyte)opacity{
for( CCNode *node in [self children] )
{
if( [node conformsToProtocol:@protocol(CCRGBAProtocol)] )
{
NSLog(@"conforms to protocol!");
[(id<CCRGBAProtocol>) node setOpacity: opacity];
}
}
}
@end
游戏层.m
-(id)init{
timer = [NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(checkIfLoaded) userInfo:nil repeats:YES];
}
-(void)checkIfLoaded{
NSLog(@"still doing stuff");
if(doneInitializing ==YES){
NSLog(@"done");
[timer invalidate];
NSLog(@"FADE NOW !!!!");
id fade = [CCFadeOut actionWithDuration:2.5];
[loadingLayer runAction:fade];
[self performSelector:@selector(removeLoadingLayer) withObject:nil afterDelay:3.5];
}
if(loadingScreenPushed == NO && doneInitializing == NO){
NSLog(@"adding Layer");
loadingScreenPushed = YES;
loadingLayer = [LoadingScreen node];
[self addChild:loadingLayer z:10];
}
}