Cocos2d-x 3.2 Lua演示样例CurrentLanguageTest(当前语言环境)
2017-06-08 09:27 tlnshuju 阅读(369) 评论(0) 编辑 收藏 举报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