bool HelloWorld::init(){
// 获得屏幕尺寸
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF *label = CCLabelTTF::create("", "", 28);
label->setPosition((ccp(winSize.width/2, winSize.height/2)));
this->addChild(label);
// 获取当前语言
LanguageType languageType = CCApplication::sharedApplication()->getCurrentLanguage();
// 返回的数据类型是一个枚举类型,我们使用switch case来判断
switch (languageType) {
case cocos2d::kLanguageChinese:
label->setString("current language is Chinese");
break;
case cocos2d::kLanguageEnglish:
label->setString("current language is English");
default:
break;
}
return true;
}
通过获取到的语言,我们就可以在其中判断使其加载不同的语言包,已到达多语言的效果。