0

我有 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
4

1 回答 1

3

self = [self init]; inGameplayLayer将永远递归。应该self = [super init];

于 2013-03-12T00:52:20.773 回答