#include "HelloWorldScene.h"
USING_NS_CC;
CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//利用CCDictionary来读取xml
CCDictionary *strings = CCDictionary::createWithContentsOfFile("strings.xml");//载入资源文件夹的strings.xml
//读取HelloWorld键中的值objectForKey根据key,获取对应的string
const char *HelloWorld = ((CCString*)strings->objectForKey("HelloWorldString"))->m_sString.c_str();
//获取屏幕的尺寸、位置信息等
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
//乱码文字
CCLabelTTF *label0 = CCLabelTTF::create("你好,世界","arial",72);
label0->setPosition(ccp(visibleSize.width/2,2*visibleSize.height/3));
this->addChild(label0);
//正常中文
CCLabelTTF *label1 = CCLabelTTF::create(HelloWorld,"arial",72);
label1->setPosition(ccp(visibleSize.width/2,visibleSize.height/3));
this->addChild(label1);
return true;
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
CCMessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
#else
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
#endif
}