代码是如下:
-(void)Language{
CCScene *sc=[CCScene node];
GameMenu *Points=[GameMenu node];
[sc addChild:Points z:1 tag:1];
[[CCDirector sharedDirector] replaceScene:[CCTransitionCrossFade transitionWithDuration:1 scene:sc]];
[self unschedule:@selector(Language)];
}
- (id)init {
self = [super init];
if (self) {
int yuyanset = [[NSUserDefaults standardUserDefaults] integerForKey:@"yuyanset"];
if (yuyanset==0) {
CCMenuItemFont *Cn=[CCMenuItemFont itemFromString:@"简体中文" target:self selector:@selector(Cn:)];
CCMenuItemFont *En=[CCMenuItemFont itemFromString:@"English" target:self selector:@selector(En:)];
CCMenu *Language=[CCMenu menuWithItems:Cn,En,nil];
[Language alignItemsVertically];
[Language alignItemsVerticallyWithPadding:25];
[self addChild:Language];
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"yuyanset"];
}else{
[self schedule:@selector(Language)];
} }
return self;
}
-(void)Cn:(id)sender{
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"yuyan"];
[self Language];
}
-(void)En:(id)sender{
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"yuyan"];
[self Language];
}
- (void)dealloc {
[super dealloc];
}
[self Language]与[self schedule:@selector(Language)];的区别
[self Language]是OBJC的调用方法!
[self schedule:@selector(Language)]; 是cocos2d选择器(selector)或者用@selector(...)关键词的方式来预定
更新方法;
如果上面代码用[self Language]你会看到一个黑屏!没有其他的效果!
这样你只有使用[self schedule:@selector(Language)]; 才能进行跳转!才能达到预期的效果!