Cocos2d Part 8 (Surfing Scenes)

 

HelloWorldLayer.m代码

 

+(CCScene *) scene
{
	CCScene *scene = [CCScene node];
	HelloWorldLayer *layer = [HelloWorldLayer node];
     CCSprite *background=[CCSprite spriteWithFile:@"Default.png"];
    background.anchorPoint=ccp(0, 0);
    [layer addChild:background z:-1 ];
	[scene addChild: layer];
  	return scene;
}
-(void)playGame:(id)item{
    [[CCDirector sharedDirector]replaceScene:[CCTransitionJumpZoom transitionWithDuration:1 scene:[GameLayer scene]]];
}
-(void)howToPlay:(id)item{
    NSLog(@"howToPlay");
}
-(id) init
{
	
	if( (self=[super init]) ) {

        CCLabelBMFont *playTxt =[CCLabelBMFont labelWithString:@"play" fntFile:@"chicken_font.fnt"];
        CCMenuItemLabel *playMenu = [CCMenuItemLabel itemWithLabel:playTxt target:self selector:@selector(playGame:)];
        CCLabelBMFont *howToPlayTxt =[CCLabelBMFont labelWithString:@"howToPlay" fntFile:@"chicken_font.fnt"];
        CCMenuItemLabel *howToPlayMenu = [CCMenuItemLabel itemWithLabel:howToPlayTxt target:self selector:@selector(howToPlay:)];
        CCMenu *menu =[CCMenu menuWithItems:playMenu,howToPlayMenu, nil];
        [menu alignItemsVerticallyWithPadding:5];
        [self addChild:menu];
    }
	return self;
}

 GameLayer.m代码

 

+(CCScene *) scene
{
	CCScene *scene = [CCScene node];
	GameLayer *layer = [GameLayer node];
	[scene addChild: layer];
  	return scene;
}
-(void)playGame:(id)item{
    NSLog(@"Play");
}
-(id) init
{
	
	if( (self=[super init]) ) {
        
        CCLabelBMFont *playTxt =[CCLabelBMFont labelWithString:@"GameScene" fntFile:@"chicken_font.fnt"];
        CCMenuItemLabel *playMenu = [CCMenuItemLabel itemWithLabel:playTxt target:self selector:@selector(playGame:)];
        CCMenu *menu =[CCMenu menuWithItems:playMenu, nil];
        [menu alignItemsVerticallyWithPadding:5];
        [self addChild:menu];
    }
	return self;
}

你可能感兴趣的:(cocos2d)