您的位置:首页 > 移动开发

在AppDelegate中显示界面或者调用js

2016-07-31 22:04 337 查看
这两者都需要在cocos线程中执行

显示界面:

Director::getInstance()->getScheduler()->performFunctionInCocosThread([this]() {
rapidjson::Document *doc = new rapidjson::Document();
doc->Parse<0>(announceStr.c_str());
std::string title = doc->operator[]("title").GetString();
std::string content = doc->operator[]("content").GetString();

auto winSize = cocos2d::Director::getInstance()->getWinSize();
auto forcelayer = OnePiece::ResourceManager::getInstance()->LoadUIWidget("LcmForceAnnounce.json", false);
forcelayer->setSize(winSize);
forcelayer->setAnchorPoint(cocos2d::Point(0.5, 0.5));
forcelayer->setPosition(cocos2d::Point(winSize.width / 2, winSize.height / 2));
auto Panel_dialog = forcelayer->getChildByName("Panel_dialog");
Panel_dialog->setAnchorPoint(cocos2d::Point(0.5, 0.5));
Panel_dialog->setPosition(cocos2d::Point(winSize.width / 2, winSize.height / 2));
auto Panel_gray = (cocos2d::Layer*)forcelayer->getChildByName("PanelBg");
Panel_gray->setContentSize(winSize);
Panel_gray->setAnchorPoint(cocos2d::Point(0.5, 0.5));
Panel_gray->setPosition(cocos2d::Point(winSize.width / 2, winSize.height / 2));

auto dlgBg = Panel_dialog->getChildByName("dlg_bg");
auto panelFirst = dlgBg->getChildByName("panel_first");
auto labelContent = (cocos2d::Label*)panelFirst->getChildByName("label_content");
labelContent->setVisible(false);

cocos2d::Label *_contentLabel = cocos2d::Label::createWithTTF("", "common/font/DFGB_Y7_0.ttf", 18);
_contentLabel->setAnchorPoint(Point(0, 1));
_contentLabel->setPosition(labelContent->getPosition());
_contentLabel->setString(content);
// _contentLabel->setTextColor(cocos2d::Color4B::YELLOW);
_contentLabel->enableOutline(cocos2d::Color4B::BLACK, 1);
_contentLabel->setDimensions(340,200);
panelFirst->addChild(_contentLabel);

if (m_pLaunchScene != nullptr) {
CCLOG("#### lcm forbidden found ");
} else {
CCLOG("#### lcm forbidden not found ");
m_pLaunchScene = OnePiece::LaunchLayer::createScene();
Director::getInstance()->runWithScene(m_pLaunchScene);
}
auto m_pBackground = Sprite::create("res/ui/login/launchbg.jpg");
m_pBackground->setPosition(Vec2(winSize.width/2.0, winSize.height/2.0));
m_pLaunchScene->addChild(m_pBackground);
m_pLaunchScene->addChild(forcelayer, 1000000);
});

调用js的function:
Director::getInstance()->getScheduler()->performFunctionInCocosThread([]() {
ScriptingCore* sc = ScriptingCore::getInstance();
JSContext *cx = sc->getGlobalContext();

JS::RootedValue nsval(cx);
JS::RootedObject ns(cx);

JS_GetProperty(cx, sc->getGlobalObject(), "mobage", &nsval);
if (nsval != JSVAL_VOID) {
JS_ValueToObject(cx, nsval, &ns);
ScriptingCore::getInstance()->executeFunctionWithOwner(nsval, "continueTransactionBankError");
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cocos2d-x 界面 线程