当前位置:编程学习 > wap >>

[Cocos2D-X ]初窥门径(10)解决中文乱码

用资源文件保存字符串,格式UTF-8,这样读取xml文件,然后显示就不会乱码了。

这样做还有一个好处就是方便以后国际化。

xml文件:


[html]
<dict>  
    <key>Hello</key>  
    <string>Hi~可以正常显示中文了!</string>  
</dict> 

<dict>
 <key>Hello</key>
 <string>Hi~可以正常显示中文了!</string>
</dict>
显示:


[cpp]
const char* Hello = ((CCString*)strings->objectForKey("Hello"))->m_sString.c_str(); 
CCLabelTTF* pLabel1=CCLabelTTF::create(Hello,"Arial",24); 
pLabel1->setPosition(ccp(size.width/2,size.height/2)); 
this->addChild(pLabel1); 

 const char* Hello = ((CCString*)strings->objectForKey("Hello"))->m_sString.c_str();
 CCLabelTTF* pLabel1=CCLabelTTF::create(Hello,"Arial",24);
 pLabel1->setPosition(ccp(size.width/2,size.height/2));
 this->addChild(pLabel1);
效果:

 \

 

 

 

补充:移动开发 , 其他 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,