我有1个包含两个图层的场景。一个名为BackgroundLayer,另一个名为GameplayLayer。背景图层如下所示:
-(id) init{
self = [super init];
if(self != nil){
CCSprite * backgroundImage;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
backgroundImage = [CCSprite spriteWithFile:@"backgroundr.png"];
}
else{
backgroundImage = [CCSprite spriteWithFile:@"background.png"];
}
CGSize screenSize = [[CCDirector sharedDirector] winSize];
[backgroundImage setPosition:CGPointMake(screenSize.width/2, screenSize.height/2)];
[self addChild:backgroundImage];
}
return self;}
这很好用。但问题是,GameplayLayer导致游戏崩溃。 GameplayLayer看起来像这样:
-(id) init{
self = [self init];
if( self != nil){
}
return self;
}
游戏场景也是如此:
-(id) init{
self = [super init];
if(self != nil){
BackgroundLayer * backgroundLayer = [BackgroundLayer node];
[self addChild:backgroundLayer z:0];
GameplayLayer * gameplayLayer = [GameplayLayer node];
[self addChild:gameplayLayer z:5];
}
return self;
}
我真的没有看到这里的问题。但如果我删除 - (id)init它不会崩溃。
有什么想法?
以下是日志的最后几行:
2013-03-12 00:41:41.371 CocoTest[3574:c07] cocos2d: **** WARNING **** CC_ENABLE_GL_STATE_CACHE is disabled. To improve performance, enable it by editing ccConfig.h
2013-03-12 00:41:41.371 CocoTest[3574:c07] cocos2d: cocos2d v2.0.0
2013-03-12 00:41:41.371 CocoTest[3574:c07] cocos2d: Using Director Type:CCDirectorDisplayLink
答案 0 :(得分:3)
self = [self init];
中的 GameplayLayer
将永远递归。应为self = [super init];