[size=small;]原地址:[/size][url=http://hi.baidu.com/you5a_com/item/1c57d52dba2cc90672863e4d]http://hi.baidu.com/you5a_com/item/1c57d52dba2cc90672863e4d[/url]
[b]场景初始化:[/b]
第一个创建场景的地方是在AppDelegate中aplicationDidFinishLaunching方法结束处.
[[CCDirector sharedDirector] runWithScene:[HelloWorld scene]];
用replaceScene方法来替换已有的场景:
[[CCDirector sharedDirector] replaceScene:[HelloWorld scene]];
[b]场景上下左右场景切入方式:[/b]
[b]暂停、返回[/b]
[[CCDirector sharedDirector] pause];
[[CCDirector sharedDirector] resume];
[b]推进(Pushing)和弹出(Popping)场景:[/b]
设置场景:
[[CCDirector sharedDirector] pushScene:[Settings scene]];
关闭场景:
[[CCDirector sharedDirector] popScene];
[b]用CCDirector replaceScene方法替换场景时, 每个节点都会调用CCNode所带的三个方法.[/b]
[b]这三个方法是: onEnter, onEnterTransitionDidFinish和onExit[/b]
警告:永远不要在一个节点的init方法中调用CCDirector的replaceScene方法
[b]场景初始化:[/b]
+(id) scene {
CCScene *scene = [CCScene node];
CCLayer* layer = [HelloWorld node];
[scene addChild:layer];
return scene;
}
第一个创建场景的地方是在AppDelegate中aplicationDidFinishLaunching方法结束处.
[[CCDirector sharedDirector] runWithScene:[HelloWorld scene]];
用replaceScene方法来替换已有的场景:
[[CCDirector sharedDirector] replaceScene:[HelloWorld scene]];
[b]场景上下左右场景切入方式:[/b]
//从右往左切入
-(void)TurnToNextScene:(id)sender{
[[SimpleAudioEngine sharedEngine]stopBackgroundMusic];
[[CCDirector sharedDirector]replaceScene:[CCTransitionSlideInR transitionWithDuration:1.0 scene:[PaperWindWill_iPhone scene]]];
}
//从左往右切入
-(void)TurnToPresviousScene:(id)sender{
[[SimpleAudioEngine sharedEngine]stopBackgroundMusic];
[[CCDirector sharedDirector]replaceScene:[CCTransitionSlideInL transitionWithDuration:1.0 scene:[LittleCarpenter_iPhone scene]]];
}
//从下往上切入
-(void)TurnToMenuScene:(id)sender{
[[SimpleAudioEngine sharedEngine]stopBackgroundMusic];
[[CCDirector sharedDirector]replaceScene:[CCTransitionSlideInT transitionWithDuration:1.0 scene:[Menu_iPhone scene]]];
}
//从上往下切入
[[CCDirector sharedDirector]replaceScene:[CCTransitionSlideInB transitionWithDuration:1.0scene:[Menu_iPhone scene]];
[b]暂停、返回[/b]
[[CCDirector sharedDirector] pause];
[[CCDirector sharedDirector] resume];
[b]推进(Pushing)和弹出(Popping)场景:[/b]
设置场景:
[[CCDirector sharedDirector] pushScene:[Settings scene]];
关闭场景:
[[CCDirector sharedDirector] popScene];
[b]用CCDirector replaceScene方法替换场景时, 每个节点都会调用CCNode所带的三个方法.[/b]
[b]这三个方法是: onEnter, onEnterTransitionDidFinish和onExit[/b]
-(void) onEnter {
// 节点调用init方法以后将会调用此方法
// 如果使用了CCTransitionScene,将会在过渡效果开始以后调用此方法
[super onEnter];
}
-(void) onEnterTransitionDidFinish {
// 调用onEnter以后将会调用此方法
// 如果使用了CCTransitionScene,将会在过渡效果结束以后调用此方法
[super onEnterTransitionDidFinish];
}
-(void) onExit {
// 节点调用dealloc方法之前将会调用此方法
// 如果使用了CCTransitionScene,将会在过渡效果结束以后调用此方法
[super onExit];
}
警告:永远不要在一个节点的init方法中调用CCDirector的replaceScene方法