#include "HelloWorldScene.h"
#include "TestButton.h"
USING_NS_CC;
#define TESTBUTTONTAG 10086
Scene* HelloWorld::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
auto 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()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
std::string filePath = FileUtils::getInstance()->fullPathForFilename("test.json");
std::string contentStr = FileUtils::getInstance()->getStringFromFile(filePath);
log("%s",contentStr.c_str());
_doc.Parse<0>(contentStr.c_str());
m_btnDataArray = _doc["btnData"];
if (_doc["boolean"].GetBool()) {
log("getBoolean is true");
}
log("PI = %f",_doc["number"].GetDouble());
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
m_label = Label::createWithSystemFont("helkyle.tk", "Arial", 80);
m_label -> setPosition(Point(visibleSize.width * 0.5, visibleSize.height * 0.75));
this -> addChild(m_label);
Point point[] = {Point(visibleSize.width * 0.25, visibleSize.height * 0.50),Point(visibleSize.width * 0.75, visibleSize.height * 0.50),
Point(visibleSize.width * 0.25, visibleSize.height * 0.20),Point(visibleSize.width * 0.75, visibleSize.height * 0.20)};
for (int i = 0; i < 4; i++) {
auto btn = TestButton::create("box.png");
btn -> setPosition(point[i]);
btn -> setTag(TESTBUTTONTAG + i);
this -> addChild(btn);
}
this -> scheduleOnce(schedule_selector(HelloWorld::initJsonData), 2);
return true;
}
void HelloWorld::initJsonData(float dt)
{
m_label -> setString(_doc["SceneTitle"].GetString());
for (int i = 0; i < 4; i ++) {
auto btn = (TestButton *)this -> getChildByTag(TESTBUTTONTAG + i);
btn -> initData(m_btnDataArray[i]);
}
}
- 1
- 2
前往页