Cocos2d-x3.2 获取系统语言环境

//GameScene.h

#include "cocos2d.h"

class GameScene : public cocos2d::Layer
{
public:
    static cocos2d::Scene* createScene();
    
    virtual bool init();
    
    void menuCallback(cocos2d::Ref* pSender);
    
    CREATE_FUNC(GameScene);
};




//GameScene.cpp

//功能:运行,显示当前系统语言类型

#include "GameScene.h"

USING_NS_CC;

cocos2d::Scene* GameScene::createScene()
{
    auto scene = Scene::create();   //创建一个场景
    auto layer = GameScene::create();   //创建一个图层
    scene->addChild(layer);
    return scene;
}

//初始化当前的图层
bool GameScene::init()
{
    if(!Layer::init())      //初始化父类
        return false;
    
    //获取屏幕大小
    Size visibleSize = Director::getInstance()->getVisibleSize();
    //auto size = Director::getInstance()->getWinSize();
    //添加一个图片精灵
    auto sprite = Sprite::create("OnePiece_1.png");
    sprite->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2));
    this->addChild(sprite);
    
    auto label = Label::createWithSystemFont("", "Marker Felt", 45);
    label->setAnchorPoint(Vec2::ZERO);
    label->setPosition(Vec2(0, visibleSize.height*0.5));
    this->addChild(label);
    
    auto curLanguage = Application::getInstance()->getCurrentLanguage();
    switch (curLanguage) {
        case cocos2d::LanguageType::CHINESE:
            label->setString("CHINESE");
            break;
            
        case cocos2d::LanguageType::ENGLISH:
            label->setString("ENGLISH");
            break;
            
        //......................
            
        default:
            break;
    }
    
    
    return true;
}


你可能感兴趣的:(Cocos2d-x3.2 获取系统语言环境)