• 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
    



  • 相关阅读:
    Linux pwn入门教程(1)——栈溢出基础
    Java代码审计入门篇
    利用Burp Suite攻击Web应用
    记一次对某企业的渗透测试实战
    Python 绝技 —— UDP 服务器与客户端
    SQL注入之重新认识
    文件上传和WAF的攻与防
    phpMyAdmin 4.7.x CSRF 漏洞利用
    Powershell渗透测试系列–进阶篇
    AFN检測网络情况
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/6961157.html
Copyright © 2020-2023  润新知