关于cocos2d-iphone的错误

时间:2011-04-03 19:01:19

标签: iphone cocos2d-iphone

我有三层 - a,b和c

主要代码:

-(id) init
{
        // always call "super" init
        // Apple recommends to re-assign "self" with the "super" return value
        if( (self=[super init] )) {
                CCSprite *sp = [CCSprite spriteWithFile:@"bg.png"];
                sp.anchorPoint = CGPointZero;
                [self addChild:sp z:0 tag:1];

                [CCMenuItemFont setFontName: @"Georgia"];
                [CCMenuItemFont setFontSize:25];

                CCMenuItem *newGame = [CCMenuItemFont itemFromString:@"New Games" target:self selector:@selector(newGame:)];
                CCMenuItem *helpGame = [CCMenuItemFont itemFromString:@"Help" target:self selector:@selector(helpGame:)];

                CCMenu *menulist = [CCMenu menuWithItems:newGame, helpGame, nil];
                [menulist alignItemsVertically];

                [self addChild:menulist z:1 tag:2];

        }
        return self;
}

- (void) newGame:(id) sender
{
        CCScene *newscene = [CCScene node];
        [newscene addChild:[BScene node]];
        [[CCDirector sharedDirector] replaceScene:[CCTransitionShrinkGrow transitionWithDuration:1.2f scene:newscene]];

}

- (void) helpGame:(id) sender
{
        CCScene *newscene = [CCScene node];
        [newscene addChild:[CScene node]];
        [[CCDirector sharedDirector] replaceScene:[CCTransitionShrinkGrow transitionWithDuration:1.2f scene:newscene]];

}

b的主要代码

-(id) init
{
        if( (self=[super init] )) {
                CCSprite *sp = [CCSprite spriteWithFile:@"bg.png"];
                sp.anchorPoint = CGPointZero;
                [self addChild:sp z:0 tag:1];

                CCBitmapFontAtlas *label = [CCBitmapFontAtlas bitmapFontAtlasWithString:@"Go back" fntFile:@"font01.fnt"];
                CCMenuItemLabel *back = [CCMenuItemLabel itemWithLabel:label target:self selector:@selector(backCallback:)];
                back.scale = 0.8;
               [self addChild:back z:1 tag:2];
        }
        return self;
}

- (void) dealloc
{
        [super dealloc];
}

-(void) backCallback: (id) sender
{
        CCScene *sc = [CCScene node];
        [sc addChild:[AScene node]];

        [[CCDirector sharedDirector] replaceScene:  [CCTransitionShrinkGrow transitionWithDuration:1.2f scene:sc]];        
}

当我点击startGame进入b时,应用程序将退出,但如果我从b中删除以下代码,则该功能运行正常,我可以进入b

CCBitmapFontAtlas *label = [CCBitmapFontAtlas bitmapFontAtlasWithString:@"Go back" fntFile:@"font01.fnt"];
            CCMenuItemLabel *back = [CCMenuItemLabel itemWithLabel:label target:self selector:@selector(backCallback:)];
            back.scale = 0.8;
           [self addChild:back z:1 tag:2];

那有什么问题呢?非常感谢

1 个答案:

答案 0 :(得分:1)

尝试使用CCLabelTTF,我总是使用它并且永远不会有问题。例如:

CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello" fontName:@"Arial" fontSize:20];

希望这有帮助!