cocos2dx 3.0 CocoStudio1.4.1
做界面的时候用到了CocoStudio生成的UI.json文件,需要做语言本地化,论坛中有朋友给出了方法:
将本地化的图片设定格式,英文的叫button_store_normal.en.png 中文的叫button_store_normal.zh.png ......
按照这种规则,根据需要的语言来加载不同的图片
我们用到的是另一种方法:
修改json文件,这里并不是真正的修改json文件,只是在读取json文件到内存后,不是立即交予GUIReader生成widget,而是根据需要的语言, 替换json文件中对应的资源路径
资源目录如下:
Resource/data/UI.json
Resource/data/pic //UI.json用到的无需本地化的图片目录
Resource/data/local_en //存放英文版的图片资源
Resource/data/local_zh //存放中文版的图片资源
......
JSON文件如下:
"texturesPng": [ "pic/ui/weaponscene/bg.png", "pic/ui/weaponscene/weapon_sel_close.png", "pic/ui/weaponscene/weapon_sel_close1.png", "pic/ui/weaponscene/slider_bar.png", "pic/ui/weaponscene/slider_btn.png", "pic/ui/weaponscene/weapon_sel_bg.png", "pic/weapon_1.png", "pic/ui/bullet_flag.png", "pic/ui/weaponscene/money_buy_bullet.png", "pic/ui/weaponscene/money_buy_bullet1.png", "local_en/weapon_select_scene/jiemian_upgrade_5.png", "local_en/weapon_select_scene/jiemian_upgrade_5_1.png", "pic/ui/weaponscene/progress2.png", "pic/ui/weaponscene/progress1.png", "pic/ui/weaponscene/progress.png", "local_en/weapon_select_scene/jiemian_sttack_4.png", "local_en/weapon_select_scene/jiemian_xuanzhong_6_5.png", "local_en/weapon_select_scene/jiemian_xuanzhong_6_6.png", "local_en/weapon_select_scene/jiemian_xuanzhong_6_7.png", "local_en/weapon_select_scene/jiemian_xuanzhong_6_8.png", "local_en/weapon_select_scene/jiemian_go.png", "local_en/weapon_select_scene/jiemian_go_1.png", "local_en/weapon_select_scene/jiemian_shop.png", "local_en/weapon_select_scene/jiemian_shop_1.png" ...... ],
pic/ui/*.png属于不需要多语言处理的
local_en/*.png是我们默认设计的语言目录
读取完UI.json文件后,我们将"local_en/"替换为我们需要的语言,如"local_zh/", 就可以了,剩下的就是确定语言的问题了。
如果大家有更好的办法,也和我分享一下