我有一个“场景”类,它添加了几个图层。我想在游戏结束时从其中一层添加最后一层(以显示不同的分数)(因此该层将使用委托调用 Scene 类,并且 Scene 类应添加这个新层:“ LevelCompleteLayer”)。
但是 Scene 类中的方法没有收到调用。你知道为什么吗?其他代表(层之间)工作正常,但这个(从层到场景)没有。
这是代码:
//in Level1Scene.h :
@interface Level1Scene : CCScene <CompleteLayerDelegate>{
//in Level1Scene.mh :
@implementation Level1Scene
@synthesize levelComplete;
-(void)showLevelCompleteLayer {
CCLOG(@"delegateCompleteLayer showLevelCompleteLayer!!!");//does not show up
[self addChild:levelComplete z:5000];//is not added
}
-(id)init {
if ((self = [super init])) {
ScoreLayer *scoreLayer = [ScoreLayer node];
layer = [[Level1Layer alloc] initWithBackgroundImage:background.backgroundImage];
levelComplete = [[LevelComplete alloc] init];
layer.delegate = scoreLayer;//works fine
layer.delegateCompleteLayer = self; //does not respond
scoreLayer.delegate = layer;//works fine
//...
}
return self;
}
//in Level1Layer.m :
[delegateCompleteLayer showLevelCompleteLayer];
//in GameProtocols.h :
@protocol CompleteLayerDelegate
-(void)showLevelCompleteLayer;
@end
谢谢你的帮助