【发布时间】:2011-04-03 19:01:18
【问题描述】:
我有三层——a、b 和 c
a的主要代码:
-(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];
那么它有什么问题呢?非常感谢
【问题讨论】:
-
您是否将 font01.fnt 添加到您的项目中?
-
当然,我补充说,但它仍然是相同的错误,即使我将 b 的代码 '-(id) init' 替换为 a's,但它仍然显示相同的错误,所以我该怎么办?
-
我真的不知道...还有一个问题:您使用的是什么版本的 Cocos2D,因为我在几个版本之前也遇到了同样的问题。对不起,我不能更有帮助。 :\
标签: iphone cocos2d-iphone