国际化string
字符串显示的载体Label
Cocos2d-x 3.3中的Label的主要API:
-
Label::createWithTTF,使用libfreetype2创建字体
-
Label::createWithSystemFont,创建系统原生字体
-
Label::createWithCharMap,一般用来显示数字
国际化思路
-
思路:类似android的value-en/string.xml value-zh/string.xml
-
cpp-tests提供的原料:LabelTTFUnicodeNew::LabelTTFUnicodeNew()
国际化实现
1. 根据系统语言判断选取对应的string.xml,简单包装了下,单例,跟label合起来用步骤还是有些繁琐
.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#ifndef__MyStringUtils__
#define__MyStringUtils__
#include"cocos2d.h"
USING_NS_CC;
class
MyStringUtils{
private
:
static
MyStringUtils*instance;
ValueMapstrings;
MyStringUtils();
CC_DISALLOW_COPY_AND_ASSIGN(MyStringUtils);
public
:
MyStringUtils*getInstance();
static
void
destroyInstance();
~MyStringUtils();
std::stringgetStringForKey(
const
std::string&key);
};
#endif
|