DataParser/Classes/HelloWorldScene.cpp
// on "init" you need to initialize your instance
on "init" you need to initialize your instance
on " init " you need to initialize your instance
bool HelloWorld::init()
{
    const char* file = "content.txt";
    data1_ = new struct DataParserBase;
    data1_->initWithFile(file);
    data1_->printContent();
    data2_ = new struct DataParserText;
    data2_->initWithFile(file);
    data2_->setLanguage(DataParserText::LANGUAGE::CN);
    string str1 = data2_->textFromFile("button", "confirm");
    string str2 = data2_->textFromFile("button", "cancel");
    log("Find by name 'confirm'：%s ", str1.c_str());
    log("Find by name 'cancel'：%s ", str2.c_str());
    string str3 = data2_->textFromFile("button", 0);
    string str4 = data2_->textFromFile("button", 1);
    log("Find by key '0'：%s ", str3.c_str());
    log("Find by key '1'：%s ", str4.c_str());
    if ( !Layer::init() )
    {
        return false;
    }
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    auto closeItem = MenuItemImage::create(
                                           "CloseNormal.png",
                                           "CloseSelected.png",
                                           CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
	closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
                                origin.y + closeItem->getContentSize().height/2));
    auto menu = Menu::create(closeItem, NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu, 1);
    auto label = Label::createWithTTF("Data Parser", "fonts/Marker Felt.ttf", 44);
    label->setPosition(Vec2(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - label->getContentSize().height));
    this->addChild(label, 1);
    return true;
}
bool HelloWorld :: init ( ) { const char * file = " " ; data1_ = new struct DataParserBase ; data1_ -> initWithFile ( file ) ; data1_ -> printContent ( ) ; data2_ = new struct DataParserText ; data2_ -> initWithFile ( file ) ; data2_ -> setLanguage ( DataParserText :: LANGUAGE :: CN ) ; string str1 = data2_ -> textFromFile ( " " , " " ) ; string str2 = data2_ -> textFromFile ( " " , " " ) ; log ( " s r1.c _ str() ) ; log ( " s r2.c _ str() ) ; string str3 = data2_ -> textFromFile ( " " , 0 ) ; string str4 = data2_ -> textFromFile ( " " , 1 ) ; log ( " s r3.c _ str() ) ; log ( " s r4.c _ str() ) ; if ( ! Layer :: init ( ) ) { return false ; } Size visibleSize = Director :: getInstance ( ) -> getVisibleSize ( ) ; Vec2 origin = Director :: getInstance ( ) -> getVisibleOrigin ( ) ; auto closeItem = MenuItemImage :: create ( " " , " " , CC_CALLBACK_1 ( HelloWorld :: menuCloseCallback , this ) ) ; closeItem -> setPosition ( Vec2 ( origin . x + visibleSize . width - closeItem -> getContentSize ( ) . width / 2 , origin . y + closeItem -> getContentSize ( ) . height / 2 ) ) ; auto menu = Menu :: create ( closeItem , NULL ) ; menu -> setPosition ( Vec2 :: ZERO ) ; this -> addChild ( menu , 1 ) ; auto label = Label :: createWithTTF ( " " , " " , 44 ) ; label -> setPosition ( Vec2 ( origin . x + visibleSize . width / 2 , origin . y + visibleSize . height - label -> getContentSize ( ) . height ) ) ; this -> addChild ( label , 1 ) ; return true ; }
on "init" you need to initialize your instance
on " init " you need to initialize your instance
// test  -------------------------- ////////////////////////////// // 1. super init first ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program //    you may modify it. // add a "close" icon to exit the progress. it's an autorelease object // create menu, it's an autorelease object ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label // position the label on the center of the screen // add the label as a child to this layer