1

我在使用 Cocos2d 2.0 版本时遇到了大麻烦 =(

问题:启动应用程序后,我的游戏场景没有出现在屏幕上,无论我做什么,都有一个地狱般的黑屏。

从我的代码开始。

如果你们能帮助我,我将不胜感激 =D 谢谢!

//AppDelegate from cocos2d basic template, I change this line
[director_ pushScene:[GameScene node]];

//my GameScene class implementation
- (id)init
{
   if(self != nil)
    {
        BackgroundLayer *backgroundLayer = [BackgroundLayer node];
        [self addChild:backgroundLayer z:0];
    }

    return self;
}

//then, my BackgroundLayer class implementation
- (id)init
{
    if(self != nil)
    {
        CCSprite *backgroundImage = [CCSprite spriteWithFile:@"backgroundiPhone.png"];

        CGSize screenSize = [[CCDirector sharedDirector] winSize];
        [backgroundImage setPosition:CGPointMake(screenSize.width / 2, screenSize.height / 2)];
        //yea the image is in the project, maybe if I add some color at the sprite to be sure?

        [self addChild:backgroundImage z:0 tag:0];
    }

    return self;
}
4

1 回答 1

1

你为什么不在你的方法中调用init父母init?将此行添加到 init 方法的开头。

self = [super init];
于 2012-11-20T04:31:55.540 回答