• Cocos2d-x 3.2 Lua演示样例CurrentLanguageTest(当前语言环境)


    Cocos2d-x 3.2 Lua演示样例CurrentLanguageTest(当前语言环境)


    转载请注明:IT_xiao小巫

        本篇博客介绍Cocos2d-x 3.2给我们提供的一个样例。获取当前程序的语言环境。能够通过下面方法实现:

     local currentLanguageType = cc.Application:getInstance():getCurrentLanguage()


    样例效果图例如以下:


    演示样例代码:

    --[[
    ==================
    CurrentLanguageTest.lua
    当前语言环境測试
    ==================
    ]]--
    local function CurrentLanguageTest()
        local ret = cc.Layer:create()-- 创建层
        local  label = cc.Label:createWithTTF("Current language Test", s_arialPath, 28)--标签
        ret:addChild(label, 0)--加入子节点
        label:setAnchorPoint(cc.p(0.5, 0.5))--设置锚点
        label:setPosition( cc.p(VisibleRect:center().x, VisibleRect:top().y-50) )--设置位置
    
        local labelLanguage = cc.Label:createWithTTF("", s_arialPath, 20) -- 显示语言的标签
        labelLanguage:setAnchorPoint(cc.p(0.5, 0.5))--设置锚点
        labelLanguage:setPosition(VisibleRect:center())--设置位置。VisibleRect參考VisibleRect.lua文件
    
        -- 获取系统应用程序的当前语言环境
        local currentLanguageType = cc.Application:getInstance():getCurrentLanguage()
    
        -- 英文
        if currentLanguageType == cc.LANGUAGE_ENGLISH then
            labelLanguage:setString("current language is English")
        elseif currentLanguageType == cc.LANGUAGE_CHINESE then
        -- 中文
            labelLanguage:setString("current language is Chinese")
        elseif currentLanguageType == cc.LANGUAGE_FRENCH then
        -- 法文
            labelLanguage:setString("current language is French")
        elseif currentLanguageType == cc.LANGUAGE_GERMAN then
            labelLanguage:setString("current language is German")
        -- 德语
        elseif currentLanguageType == cc.LANGUAGE_ITALIAN then
            labelLanguage:setString("current language is Italian")
        elseif currentLanguageType == cc.LANGUAGE_RUSSIAN then
        -- 俄罗斯
            labelLanguage:setString("current language is Russian")
        elseif currentLanguageType == cc.LANGUAGE_SPANISH then
        -- 西班牙语
            labelLanguage:setString("current language is Spanish")
        elseif currentLanguageType == cc.LANGUAGE_KOREAN then
        -- 韩语
            labelLanguage:setString("current language is Korean")
        elseif currentLanguageType == cc.LANGUAGE_JAPANESE then
        -- 日语
            labelLanguage:setString("current language is Japanese")
        elseif currentLanguageType == cc.LANGUAGE_HUNGARIAN then
        --  匈牙利语
            labelLanguage:setString("current language is Hungarian")
        elseif currentLanguageType == cc.LANGUAGE_PORTUGUESE then
        -- 葡萄牙
            labelLanguage:setString("current language is Portuguese")
        elseif currentLanguageType == cc.LANGUAGE_ARABIC then
        -- 阿拉伯语
            labelLanguage:setString("current language is Arabic")
        end
        ret:addChild(labelLanguage)
        return ret
    end
    
    -- 測试方法
    function CurrentLanguageTestMain()
        local scene = cc.Scene:create()--创建场景
        local pLayer = CurrentLanguageTest() -- 层
        scene:addChild(pLayer)-- 加入层到场景
        scene:addChild(CreateBackMenuItem())
        return scene
    end
    



  • 相关阅读:
    Storyboard中segue使用总结
    Present ViewController Modally
    UILabel设置富文本格式显示
    objective-c 中随机数的用法 (3种:arc4random() 、random()、CCRANDOM_0_1() )
    ios中static的作用
    NSBundle的使用,注意mainBundle和Custom Bundle的区别
    OC的基础语法OC继承和复合语言特性目标动作回调
    动态规划-被3整除的子序列
    A
    Coins POJ
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/6961157.html
Copyright © 2020-2023  润新知