i have three layers -- a, b and c
main code of 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]];
}
main code of 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) de开发者_运维技巧alloc
{
[super dealloc];
}
-(void) backCallback: (id) sender
{
CCScene *sc = [CCScene node];
[sc addChild:[AScene node]];
[[CCDirector sharedDirector] replaceScene: [CCTransitionShrinkGrow transitionWithDuration:1.2f scene:sc]];
}
the app will quit when i click the startGame for going into b,but if i remove the following code from b,the function runs ok,i can go into 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];
so what is wrong with it? thanks a lot
Try using CCLabelTTF, I always use it and never have problems. Example:
CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello" fontName:@"Arial" fontSize:20];
Hope this helps!
精彩评论