gpt4 book ai didi

ios - Cocos2D 在 -(id) 初始化时崩溃

转载 作者:行者123 更新时间:2023-11-28 20:22:35 25 4
gpt4 key购买 nike

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

最佳答案

GameplayLayer 中的

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

关于ios - Cocos2D 在 -(id) 初始化时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15351359/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com