在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");
}
});
显示界面:
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");
}
});
相关文章推荐
- App调用系统Camera拍照或者从Gallery选取图片,返回时先显示手机Launcher或者前一个界面,再跳转到当前activity
- 如何在ViewController里调用app delegate里自己写的的方法或者系统的方法
- js手机界面调用安卓app
- MFC中界面按钮调用(显示)对话框功能实现
- Asp.net 中在调用Button事件前用js对界面进行检查
- html中用js调用ASP文件 实现静态页面动态显示
- html中用js调用ASP文件 实现静态页面动态显示
- JS设置隐藏或者显示,不刷新页面的情况下动态设置其显示或隐藏
- JS调用服务端显示查询数据
- UTF-8编码主页调用JS显示乱码问题解决办法
- utf-8页面调用gb2312页面的js显示乱码的解决方法
- EVC 非模式对话框如何显示和隐藏(或者对话框之间如何相互调用)
- delphi调用OUTLOOK发送DBGRID中的数据(注意不是OUTLOOK EXPRESS ),带显示发送邮件界面。
- js正则 - 显示或者保存正则表达式匹配的部分内容
- 怎样 在服务器端 调用js,或者 js调用服务器端的值呢?
- js屏蔽右键 显示菜单或者选择页面上的信息(FF、IE均能用)
- 解决gb2312页面调用utf-8页面的js,显示乱码!
- html中用js调用ASP文件,实现静态页面动态显示
- js脚本不好用,Web设计界面什么也不显示
- JS 得到选中的下拉列表的序号 或者 显示的内容