void HelloWorld::update(float delta) { if(m_bStart) { CCArmature *pHero = (CCArmature*)(m_pGameScene->getChildByTag(10005)->getComponent("CCArmature")->getNode()); pHero->getParent()->setPositionX(pHero->getParent()->getPositionX() + m_fSpeed); CCArmature *pEnemy = (CCArmature*)(m_pGameScene->getChildByTag(10006)->getComponent("CCArmature")->getNode()); if(ccpDistance(ccp(pHero->getParent()->getPositionX(), 0), ccp(pEnemy->getParent()->getPositionX(), 0)) < m_fAttackDis) { pHero->getAnimation()->play("attack"); pHero->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(HelloWorld::animationEvent)); m_bStart = false; } } if(m_bDead) { CCComRender *pUIRender = static_cast<CCComRender*>(m_pGameScene->getChildByTag(10007)->getComponent("GUIComponent")); UILayer *pUILayer = static_cast<UILayer*>(pUIRender->getNode()); UILoadingBar *pHPLoadingBar = static_cast<UILoadingBar*>(pUILayer->getWidgetByName("hp02_LoadingBar")); UILoadingBar *pMPLoadingBar = static_cast<UILoadingBar*>(pUILayer->getWidgetByName("mp02_LoadingBar")); pHPLoadingBar->setPercent(m_fPercentage); pMPLoadingBar->setPercent(m_fPercentage); m_fPercentage -= 2.0f; if (m_fPercentage < 0.0f) { unscheduleUpdate(); } } }
bool UIImageViewTest_Scale9::init() { if (UIScene::init()) { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); UILabel *alert = UILabel::create(); alert->setText("ImageView scale9 render"); alert->setFontName("Marker Felt"); alert->setFontSize(30); alert->setColor(ccc3(159, 168, 176)); // alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 1.75)); m_pUiLayer->addWidget(alert); // Create the ui layer UILayer *ul = UILayer::create(); ul->scheduleUpdate(); addChild(ul); // Create the imageview UIImageView *imageView = UIImageView::create(); imageView->setScale9Enabled(true); imageView->loadTexture("cocosgui/buttonHighlighted.png"); // imageView->setScale9Size(CCSizeMake(200, 85)); // imageView->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f + imageView->getRect().size.height / 4.0f)); ul->addWidget(imageView); return true; } return false; }
//-------------------------------------------------------------------------- /// <CODE-GENERATE>{GlobalClientFuncImpl} void TexasPokerHallAgentC::C_RecLogin(const LoginResult& tResult) { /// <CODE-IMPLEMENT>{RecLogin} if(tResult <= LOGIN_CREATE) { S_ReqSyncTime(); UILayer* pkMainLayer = g_pLayerManager->GetCurrentMainLayer(); if(!VeStrcmp(pkMainLayer->GetName(), Login::GetName())) { static_cast<Login*>(pkMainLayer)->IntoHall(); } else { GetPlayer()->S_ReqInitHall(); UILayer* pkLayer = g_pLayerManager->GetCurrentMainLayer(); if(pkLayer) { pkLayer->OnForceUpdate(); } } } else { g_pkGame->ShowAlert(VE_NEW HallLoginFailed(tResult)); } /// </CODE-IMPLEMENT>{RecLogin} }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// // 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 CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); ///////////////////////////// // 3. add your codes below... CCNode* gameScene = SceneReader::sharedSceneReader()->createNodeWithSceneFile("DemoCowboy.json"); addChild(gameScene); //Create player CCNode* playerNode = gameScene->getChildByTag(10004); player = new Player(playerNode); //Assign callbacks to the buttons CCNode* uiNode = gameScene->getChildByTag(10005); UILayer* ui = (UILayer*)uiNode->getComponent("GUIComponent")->getNode(); UIButton* btnLeft = (UIButton*)ui->getWidgetByName("LeftButton"); btnLeft->addTouchEventListener(this, toucheventselector(HelloWorld::onMoveLeft)); UIButton* btnRight = (UIButton*)ui->getWidgetByName("RightButton"); btnRight->addTouchEventListener(this, toucheventselector(HelloWorld::onMoveRight)); UIButton* btnFire = (UIButton*)ui->getWidgetByName("FireButton"); // btnFire->addReleaseEvent(this, coco_releaseselector(HelloWorld::onFire)); btnFire->addTouchEventListener(this, toucheventselector(HelloWorld::onFire)); //Enable update loop this->scheduleUpdate(); return true; }
void UILabel::repaint(EngineInternals &internals, const UILayer &ui) { _elements.clear(); _elementPointers.clear(); _textures.clear(); float x = 0; float y = 0; std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> convert; std::wstring result = convert.from_bytes(_text); Vector2 resolution(size.x * ui.getRatio(), size.y * ui.getRatio()); for (std::wstring::const_iterator i = result.begin(); i != result.end(); i++) { auto &g = _typeEngine.getGlyph(*i, (unsigned int)resolution.y); float x2 = x + (float)g.bitmap.left; float y2 = y + (resolution.y - (float)g.bitmap.top); Texture2D *tex; if (_textures.find(*i) != _textures.end()) { tex = _textures[*i].get(); } else { _textures[*i] = std::make_shared<Texture2D>(g.bitmap.buffer, Pixmap::Information(Metric2(g.bitmap.width, g.bitmap.height), Pixmap::Information::Format::ALPHA, 8)); tex = _textures[*i].get(); } UIElement glyph = UIElement(Vector2((float)g.bitmap.width / ui.getRatio(), (float)g.bitmap.height / ui.getRatio()), Alignment::TOP_LEFT, Vector2(x2 / ui.getRatio(), y2 / ui.getRatio()), tex); glyph.uvs[0] = Vector2(0, 0); glyph.uvs[1] = Vector2(1, 0); glyph.uvs[2] = Vector2(1, 1); glyph.uvs[3] = Vector2(0, 1); x += g.advance.x; y += g.advance.y; _elements.push_back(glyph); } for (auto &element : _elements) { _elementPointers.push_back(&element); } if (!_fixed) { size.x = x / ui.getRatio(); } }
// on "init" you need to initialize your instance void GameLoginLayer::onEnter() { UILayer* uiLayer = UILayer::create(); uiLayer->scheduleUpdate(); UILayout* ui_root =dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("plane_1.json")); uiLayer->addWidget(ui_root); UIButton *left_button = dynamic_cast<UIButton*>(uiLayer->getWidgetByName("TextButton_34")); left_button->addReleaseEvent(this, SEL_ReleaseEvent(&GameLoginLayer::loginBtnCallback)); m_CCLayer->addChild(uiLayer); }
UILayer* UILayer::create(void) { UILayer *pRet = new UILayer(); if (pRet && pRet->init()) { pRet->autorelease(); return pRet; } else { CC_SAFE_DELETE(pRet); return NULL; } }
bool LoginScene::init() { if (!CCLayer::init()) { return false; } UILayer* ui = UILayer::create(); ui->setTag(LOGIN_UI_TAG); this->addChild(ui); auto pUI = CCUIHELPER->createWidgetFromJsonFile("UI/DemoLogin/DemoLogin.json"); pUI->setTag(LOGIN_UI_WIDGET_TAG); ui->addWidget(pUI); auto pLoginBtn = dynamic_cast<UIButton*>(pUI->getChildByName("login_Button")); pLoginBtn->addReleaseEvent(this, coco_releaseselector(LoginScene::loginRelease)); auto pCloseBtn = dynamic_cast<UIButton*>(pUI->getChildByName("close_Button")); pCloseBtn->addReleaseEvent(this, coco_releaseselector(LoginScene::closeGame)); return true; }
bool GestureScene::init() { if ( !CCLayer::init() ) return false; CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); this->setTouchEnabled(true); UILayer* uiLayer = UILayer::create(); uiLayer->addWidget(GUIReader::shareReader()->widgetFromJsonFile("UI/GestureUI/GestureUI.json")); UIPanel* rootPanel = (UIPanel*)uiLayer->getWidgetByName("rootPanel"); xLabel = (UILabel*) rootPanel->getChildByName("touchXLabel"); yLabel = (UILabel*) rootPanel->getChildByName("touchYLabel"); resultLabel = (UILabel*) rootPanel->getChildByName("gestureNameLabel"); this->addChild(uiLayer, 2); return true; }
bool TestView::init(){ if ( !CCLayer::init() ) { return false; } CCSize size = CCDirector::sharedDirector()->getVisibleSize(); CCLog("winSize %f %f", size.width, size.height); UILayer *lay = UILayer::create(); addChild(lay); Widget *w = GUIReader::shareReader()->widgetFromJsonFile("testgui/LoginSence.json"); lay->addWidget(w); w->setSizeType(SIZE_ABSOLUTE); w->setSize(size); return true; }
void UILayerManager::DelLayer(const VeChar8* pcName) { if(pcName) { VeUInt32* it = m_kLayerMap.Find(pcName); if(it) { VeUInt32 u32Index = *it; if(u32Index < (m_kLayerSet.Size() - 1)) { UILayer* pkLayer = m_kLayerSet[u32Index]; UILayer* pkMove = m_kLayerSet.Back(); m_kLayerMap[pkMove->GetName()] = u32Index; m_kLayerSet[u32Index] = pkMove; m_kLayerSet.Back() = pkLayer; } m_kLayerMap.Remove(pcName); VE_SAFE_DELETE(m_kLayerSet.Back()); m_kLayerSet.PopBack(); } } }
void Scene_GameItem::onEnter() { CCLayer::onEnter(); this->initData(); //隐藏pk界面 this->setPkView(false); CCSprite* pSpriteBG = (CCSprite*)getChildByTag(eGameItemTagBg); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); //pSpriteBG->setPosition(ccp(visibleSize.width/2 , pSpriteBG->getContentSize().height/2 + origin.y)); char str1[100]={0}; switch(GameShare_Global::shareGlobal()->gameType) { case 1: sprintf(str1,"GameSceneBg1.json"); break; case Game_Jelly: sprintf(str1,"GameSceneBg2.json"); break; case Game_Fruit: sprintf(str1,"GameSceneBg3.json"); break; case Game_Link: sprintf(str1,"GameSceneBg4.json"); break; case Game_TaiKo: sprintf(str1,"GameSceneBg5.json"); break; case Game_Cir: sprintf(str1,"GameSceneBg1.json"); break; default: break; } UILayer* ul = UILayer::create(); auto myLayout = dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile(CStringUtil::convertToUIResPath(str1).c_str())); ul->addWidget(myLayout); this->addChild(ul, 0, 100); ul->setTouchEnabled(false); int nGameType = GameShare_Global::shareGlobal()->gameType; if (nGameType==1) { UIImageView* pHill = dynamic_cast<UIImageView*>(ul->getWidgetByName("san")); UIImageView* pHill2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("san2")); //CCActionInterval* actionTo = CCScaleTo::create(2.0f, 0.5f); CCActionInterval* actionBy = CCScaleBy::create(1.0f, 1.0f, 1.1f); CCActionInterval* actionBy2 = CCScaleBy::create(1.0f, 1.1f, 1.0f); CCFiniteTimeAction* seq = CCSequence::create(actionBy, actionBy->reverse(),NULL); CCActionInterval * repeatForever =CCRepeatForever::create((CCActionInterval* )seq); CCFiniteTimeAction* seq1 = CCSequence::create(actionBy2, actionBy2->reverse(),NULL); CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq1); pHill->runAction(repeatForever); pHill2->runAction(repeatForever2); } else if (nGameType==2) { UIImageView* pCloud = dynamic_cast<UIImageView*>(ul->getWidgetByName("yun2")); UIImageView* pCloud2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("yun3")); CCActionInterval* actionBy = CCScaleBy::create(1.5f, 1.2f, 1.0f); CCActionInterval* actionBy2 = CCScaleBy::create(1.5f, 1.2f, 1.0f); CCFiniteTimeAction* seq1 = CCSequence::create(actionBy, actionBy->reverse(),NULL); CCFiniteTimeAction* seq2 = CCSequence::create(actionBy2, actionBy2->reverse(),NULL); CCActionInterval * repeatForever1 =CCRepeatForever::create((CCActionInterval* )seq1); CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq2); pCloud->runAction(repeatForever1); pCloud2->runAction(repeatForever2); } else if (nGameType==3) { UIImageView* pSugar = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_15")); UIImageView* pSugar1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_20")); CCRotateBy* actionBy2 = CCRotateBy::create(1.5f, -25.0f, -25.0f); CCRotateBy* actionBy1 = CCRotateBy::create(1.5f, -25.0f, -25.0f); CCFiniteTimeAction* seq1 = CCSequence::create(actionBy2, actionBy2->reverse(), NULL); CCFiniteTimeAction* seq2 = CCSequence::create(actionBy1, actionBy1->reverse(), NULL); CCActionInterval * repeatForever1 =CCRepeatForever::create((CCActionInterval* )seq1); CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq2); pSugar->runAction(repeatForever1); pSugar1->runAction(repeatForever2); //星星 UIImageView* pXx1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_23")); UIImageView* pXx2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_32")); UIImageView* pXx3 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_35")); UIImageView* pXx4 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_39")); CCActionInterval* actionBy3 = CCScaleBy::create(1.2f, 1.3f, 1.3f); CCActionInterval* actionBy4 = CCScaleBy::create(1.2f, 1.3f, 1.3f); CCActionInterval* actionBy5 = CCScaleBy::create(1.2f, 1.3f, 1.3f); CCActionInterval* actionBy6 = CCScaleBy::create(1.2f, 1.3f, 1.3f); CCFiniteTimeAction* seq3 = CCSequence::create(actionBy3, actionBy3->reverse(),NULL); CCFiniteTimeAction* seq4 = CCSequence::create(actionBy4, actionBy4->reverse(),NULL); CCFiniteTimeAction* seq5 = CCSequence::create(actionBy5, actionBy5->reverse(),NULL); CCFiniteTimeAction* seq6 = CCSequence::create(actionBy6, actionBy6->reverse(),NULL); CCActionInterval * repeatForever3 =CCRepeatForever::create((CCActionInterval* )seq3); CCActionInterval * repeatForever4 =CCRepeatForever::create((CCActionInterval* )seq4); CCActionInterval * repeatForever5 =CCRepeatForever::create((CCActionInterval* )seq5); CCActionInterval * repeatForever6 =CCRepeatForever::create((CCActionInterval* )seq6); //pCloud->runAction(repeatForever1); pXx1->runAction(repeatForever3); pXx2->runAction(repeatForever4); pXx3->runAction(repeatForever5); pXx4->runAction(repeatForever6); } else if (nGameType==4) { UIImageView* pTree = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_8")); UIImageView* pTree1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_13")); //CCActionInterval* actionTo = CCScaleTo::create(2.0f, 0.5f); CCActionInterval* actionBy = CCScaleBy::create(1.0f, 1.0f, 1.1f); CCActionInterval* actionBy2 = CCScaleBy::create(1.0f, 1.0f, 1.1f); CCFiniteTimeAction* seq = CCSequence::create(actionBy, actionBy->reverse(),NULL); CCActionInterval * repeatForever =CCRepeatForever::create((CCActionInterval* )seq); CCFiniteTimeAction* seq1 = CCSequence::create(actionBy2, actionBy2->reverse(),NULL); CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq1); pTree->runAction(repeatForever); pTree1->runAction(repeatForever2); } else if (nGameType ==5) { UIImageView* pXx1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_38")); UIImageView* pXx2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_41")); CCActionInterval* actionBy = CCScaleBy::create(1.0f, 0.5f, 0.5f); CCActionInterval* actionBy2 = CCScaleBy::create(1.0f, 0.5f, 0.5f); CCFiniteTimeAction* seq = CCSequence::create(actionBy, actionBy->reverse(),NULL); CCActionInterval * repeatForever =CCRepeatForever::create((CCActionInterval* )seq); CCFiniteTimeAction* seq1 = CCSequence::create(actionBy2, actionBy2->reverse(),NULL); CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq1); pXx1->runAction(repeatForever); pXx2->runAction(repeatForever2); UIImageView* pUFO1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_15")); UIImageView* pUFO2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Image_21")); CCMoveBy* act1 = CCMoveBy::create(2.0, ccp(0, -25)); CCMoveBy* act2 = CCMoveBy::create(1.0, ccp(0, 25)); CCFiniteTimeAction* seq3 = CCSequence::create(act1, act1->reverse(),NULL); CCFiniteTimeAction* seq4 = CCSequence::create(act2, act2->reverse(),NULL); CCActionInterval * repeatForever3 =CCRepeatForever::create((CCActionInterval* )seq3); CCActionInterval * repeatForever4 =CCRepeatForever::create((CCActionInterval* )seq4); pUFO1->runAction(repeatForever3); pUFO2->runAction(repeatForever4); } if(nGameType ==2||nGameType ==3||nGameType ==4) { UIImageView* pMg1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("mg1")); UIImageView* pMg2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("mg2")); UIImageView* pMg3 = dynamic_cast<UIImageView*>(ul->getWidgetByName("mg3")); CCActionInterval* actionBy10 = CCScaleBy::create(1.0f, 1.0f, 1.3f); CCActionInterval* actionBy11 = CCScaleBy::create(1.0f, 1.0f, 1.3f); CCActionInterval * actionBy12 = CCSkewTo::create(1, 8, 8); CCActionInterval * actionBy13 = CCSkewTo::create(1, 0, 0); CCActionInterval * actionBy14 = CCSkewTo::create(1, -8, -8); CCFiniteTimeAction* seq10 = CCSequence::create(actionBy10, actionBy10->reverse(),NULL); CCActionInterval * repeatForever10 =CCRepeatForever::create((CCActionInterval* )seq10); CCFiniteTimeAction* seq11 = CCSequence::create(actionBy11, actionBy11->reverse(),NULL); CCActionInterval * repeatForever11 =CCRepeatForever::create((CCActionInterval* )seq11); CCFiniteTimeAction* seq12 = CCSequence::create(actionBy12, actionBy13,actionBy14,NULL); CCActionInterval * repeatForever12 =CCRepeatForever::create((CCActionInterval* )seq12); pMg1->runAction(repeatForever10); pMg2->runAction(repeatForever11); pMg3->runAction(repeatForever12); } // CCSprite* pAniSp = (CCSprite*)getChildByTag(AniLayerTag); pAniSp->stopAllActions(); CCAnimation* pAni1 = CCAnimation::create(); CCString str; for (int i = 1; i <= 4; ++i){ str.initWithFormat("role/pig_tl/%d.png",i); pAni1->addSpriteFrameWithFileName(str.getCString()); } pAni1->setDelayPerUnit(0.15f); pAni1->setLoops(1); CCActionInterval* pSeq = CCSequence::create(CCFlipX::create(false),CCAnimate::create(pAni1),CCFlipX::create(true),CCAnimate::create(pAni1),NULL); pAniSp->runAction(CCRepeatForever::create(pSeq)); pAniSp->setPosition(ccp(visibleSize.width/2 + 20,visibleSize.height - pAniSp->getContentSize().height/2 - 93 + 19 -26)); }
bool GameLayerPk2::init() { if (!CCLayer::init()) { return false; } UILayer* ul = UILayer::create(); auto myLayout = dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile(CStringUtil::convertToUIResPath("Pk2.json").c_str())); ul->addWidget(myLayout); this->addChild(ul, 0, 100); UIButton* sureBtn = dynamic_cast<UIButton*>(ul->getWidgetByName("Sure")); sureBtn->setPressedActionEnabled(true); sureBtn->addReleaseEvent(this, coco_releaseselector(GameLayerPk2::sureBtnCallback)); //设置自己的头像. UIImageView* cellBg = dynamic_cast<UIImageView*>(ul->getWidgetByName("Avatar1Bg")); CCSprite* img = CCSprite::create(); img->setContentSize(CCSize(145, 145)); img->setAnchorPoint(ccp(0, 0)); cellBg->addRenderer(img, 10); CImageDownloader::GetInstance()->SendHttpRequest(CPlayerInfoMan::sharedInstance().getPlayerInfo().strImg.c_str(), img, "1000", 1000); //设置自己的名字 UILabel* nameLabel = dynamic_cast<UILabel*>(ul->getWidgetByName("Name1Label")); nameLabel->setText(CPlayerInfoMan::sharedInstance().getPlayerInfo().strName.c_str()); //设置对方的头像 UIImageView* cellBg2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Avatar2Bg")); CCSprite* img2 = CCSprite::create(); img2->setContentSize(CCSize(145, 145)); img2->setAnchorPoint(ccp(0, 0)); cellBg2->addRenderer(img2, 10); CImageDownloader::GetInstance()->SendHttpRequest(CPkSysManager::sharedInstance().playerUrl.c_str(), img2, "1000", 1000); //设置对方名字 UILabel* nameLabel2 = dynamic_cast<UILabel*>(ul->getWidgetByName("Name2Label")); nameLabel2->setText(CPkSysManager::sharedInstance().playerName.c_str()); //设置自己的分数. CCSprite* score = NumSprite::getNumSprite(CPkSysManager::sharedInstance().myScore, "./CocoStudioResources/FriendListTimeNum", 17.0); score->setPosition(ccp(-35, 0)); UIImageView* scoreBg1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("ScoreBg")); scoreBg1->addRenderer(score, 10); //等待迎战; m_iSetTime = 1; Deng = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label1")); Dai = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label2")); Ying = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label3")); Zhan = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label4")); Dain1 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label5")); Dain2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label6")); Dain3 = dynamic_cast<UIImageView*>(ul->getWidgetByName("Label7")); CCActionInterval* actionTo = CCJumpTo::create(2, ccp(200,200),50, 4); CCActionInterval* actionBy = CCJumpBy::create(2, ccp(300,0), 50, 4); actionUp = CCJumpBy::create(0.3f, ccp(0,0), 20,1); CCActionInterval* actionByBack = actionUp->reverse(); //设置光效旋转 UIImageView* Ray2 = dynamic_cast<UIImageView*>(ul->getWidgetByName("lightimg")); CCActionInterval * rotateto = CCRotateBy::create(6.0f, 360); CCFiniteTimeAction* seq1 = CCSequence::create(rotateto,NULL); CCActionInterval * repeatForever2 =CCRepeatForever::create((CCActionInterval* )seq1); Ray2->runAction(repeatForever2); //Deng->runAction( CCSequence::create(actionUp, NULL)); //Dai->runAction( CCSequence::create(actionUp, NULL)); // for(int i = 0;i<10;i++) // { // if(i%2==0) // { // // Deng->runAction(actionByBack); // } // else{ // // Dai->runAction(actionByBack); // } // } //this->schedule(schedule_selector(GameLayerPk2::SetDDTime), 0.2f); Deng->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); Dai->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); Ying->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); Zhan->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); Dain1->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); Dain2->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); Dain3->runAction( CCSequence::create((CCActionInterval*)actionUp->copy(),NULL)); return true; }
bool LayerBaCayAvatar::init() { if (!CCLayer::init()) return false; myself = GameServer::getSingleton().getSmartFox()->MySelf(); UILayer *ul = UILayer::create(); this->myName = SceneManager::getSingleton().getMyName(); this->myAI = SceneManager::getSingleton().getMyName().c_str(); this->isSpector = GameServer::getSingleton().getSmartFox()->UserManager()->GetUserByName(myName)->IsSpectator(); btn_vaochoi = UIButton::create(); btn_vaochoi->setTouchEnabled(true); btn_vaochoi->loadTextures("ready.png", "ready_selected.png", ""); btn_vaochoi->setTitleText("Vào bàn"); btn_vaochoi->setScale(0.8); btn_vaochoi->setPosition(ccp(65,87)); btn_vaochoi->setTitleFontSize(20); btn_vaochoi->addTouchEventListener(this,toucheventselector(LayerBaCayAvatar::vaoBanChoi)); btn_vaochoi->setEnabled(false); btn_vaochoi->setTag(0); btn_dungday = UIButton::create(); btn_dungday->setTouchEnabled(true); btn_dungday->loadTextures("ready.png", "ready_selected.png", ""); btn_dungday->setTitleText("Đứng dậy"); btn_dungday->setScale(0.8); btn_dungday->setPosition(ccp(65,87)); btn_dungday->setTitleFontSize(20); btn_dungday->addTouchEventListener(this,toucheventselector(LayerBaCayAvatar::vaoBanChoi)); btn_dungday->setEnabled(false); btn_dungday->setTag(1); ul->addWidget(btn_dungday); ul->addWidget(btn_vaochoi); this->addChild(ul); this->setAnchorPoint(ccp(0, 0)); this->setPosition(ccp(0, 0)); this->myName = SceneManager::getSingleton().getMyName(); Avatar *me = new Avatar(false); // me->setTouchEnabled(false); Avatar *user1 = new Avatar(false); Avatar *user2 = new Avatar(false); Avatar *user3 = new Avatar(false); Avatar *user4 = new Avatar(false); Avatar *user5 = new Avatar(false); Avatar *user6 = new Avatar(false); me->autorelease(); user1->autorelease(); user2->autorelease(); user3->autorelease(); user4->autorelease(); user5->autorelease(); user6->autorelease(); me->setPosition(ccp(WIDTH_DESIGN/2-me->getSizeThis().width/2+25,10)); user1->setPosition(ccp(40, 110)); user2->setPosition(ccp(40, HEIGHT_DESIGN-200)); user3->setPosition(ccp(250, 360)); user4->setPosition(ccp(WIDTH_DESIGN-320, 360)); user5->setPosition(ccp(WIDTH_DESIGN-120, HEIGHT_DESIGN-200)); user6->setPosition(ccp(WIDTH_DESIGN-120,110)); me->setTag(kuser0); user1->setTag(kuser1); user2->setTag(kuser2); user3->setTag(kuser3); user4->setTag(kuser4); user5->setTag(kuser5); user6->setTag(kuser6); me->setScale(0.7); user1->setScale(0.7); user2->setScale(0.7); user3->setScale(0.7); user4->setScale(0.7); user5->setScale(0.7); user6->setScale(0.7); this->addChild(me); this->addChild(user1); this->addChild(user2); this->addChild(user3); this->addChild(user4); this->addChild(user5); this->addChild(user6); chuong = UIImageView::create(); chuong->loadTexture("Chuong.png"); chuong->setScale(0.7); chuong->setTouchEnabled(false); chuong->setVisible(false); chuong->setAnchorPoint(ccp(0,0)); chuong->setPosition(ccp(0,0)); this->addChild(chuong); listUser = ""; return true; }
TanSuoLayer::TanSuoLayer() { m_nFontSize = 24; m_nMaxCountDestroy = 3; m_bIsJieFeng = false; m_nSelectProId = -1; mBg = BaseSprite::create("xunbao_bg.png"); addChild(mBg); mBg->setPosition(ccp(mWinSize.width/2, mBg->getContentSize().height/2)); mMainMenu = CCMenu::create(); mBg->addChild(mMainMenu, 10); mMainMenu->setPosition(ccp(0,0)); CCMenuItemImage *yijian = CCMenuItemImage::create( "xunbao_anniu_yijianxunbao.png", "xunbao_anniu_yijianxunbao_select.png", this, menu_selector(TanSuoLayer::menuItemClicked_TanSuo)); mMainMenu->addChild(yijian, 0, Tag_MenuItem_YiJianTanSuo); yijian->setPosition(ccp(548,mBg->getContentSize().height-674)); Button *tansuo = Button::create(); tansuo->loadTextures("xunbao_anniu_xunbao.png","xunbao_anniu_xunbao_select.png","xunbao_anniu_xunbao_select.png",UI_TEX_TYPE_LOCAL); /*CCMenuItemImage *tansuo = CCMenuItemImage::create( "xunbao_anniu_xunbao.png", "xunbao_anniu_xunbao_select.png", this, menu_selector(TanSuoLayer::menuItemClicked_TanSuo));*/ tansuo->addTouchEventListener(this,SEL_TouchEvent(&TanSuoLayer::clickXunBao)); UILayer* layer = UILayer::create(); layer->ignoreAnchorPointForPosition(false); layer->setContentSize(tansuo->getContentSize()); layer->setAnchorPoint(ccp(0.5,0.5)); layer->addWidget(tansuo); layer->setPosition(320,mBg->getContentSize().height-674);//以前cpp(x,y) 现在左边 都是Point 比如颜色 ccWHITE 也改成了Color3B::WHITE mBg->addChild(layer); tansuo->setPosition(ccp(tansuo->getContentSize().width / 2 , tansuo->getContentSize().height / 2)); m_sXunBaoSpr = CCSprite::create("xunbao_anniu_xunbao_xiaoguo.png"); m_sXunBaoSpr->setPosition(ccp(320,mBg->getContentSize().height-674)); mBg->addChild(m_sXunBaoSpr); m_sXunBaoSpr->runAction(CCRepeatForever::create(CCSequence::create(CCFadeOut::create(1.0f),CCFadeIn::create(1.0f),NULL))); //mMainMenu->addChild(tansuo, 0, Tag_MenuItem_TanSuo); //tansuo->setPosition(ccp(320,mBg->getContentSize().height-674)); { CCMenuItemImage *jiefen = CCMenuItemImage::create( "xunbao_anniu_jiechufengyin.png", "xunbao_anniu_jiechufengyin_select.png", this, menu_selector(TanSuoLayer::menuItemClicked_TanSuo)); mMainMenu->addChild(jiefen, 0, Tag_MenuItem_JieFen); jiefen->setPosition(ccp(320,mBg->getContentSize().height-437)); jiefen->setVisible(false); CCSprite *img = CCSprite::create("xunbao_anniu_jiechufengyin_xiaoguo.png"); jiefen->addChild(img); img->setPosition(ccp(jiefen->getContentSize().width/2, jiefen->getContentSize().height/2)); img->runAction(CCRepeatForever::create(CCSequence::create( CCFadeTo::create(1, 50), CCFadeTo::create(1, 255), NULL))); } mMainMenu->setVisible(false); //title CCLabelTTF *tilte = CCLabelTTF::create(LFStrings::getValue("XunBaoShuoMing").c_str(), fontStr_kaiti, m_nFontSize); mBg->addChild(tilte); tilte->setColor(fonColor_PuTong); tilte->setPosition(ccp(mBg->getContentSize().width/2, mBg->getContentSize().height-110)); //2 CCLabelTTF *la1 = CCLabelTTF::create(LFStrings::getValue("XunBaoJieFeng").c_str(), fontStr_kaiti, m_nFontSize); mBg->addChild(la1); la1->setAnchorPoint(ccp(0, 0.5)); la1->setColor(fonColor_CiYao); la1->setPosition(ccp(134, mBg->getContentSize().height-140)); CCLabelTTF *la2 = CCLabelTTF::create((LFStrings::getValue("shenbing")+LFStrings::getValue("zhuangbei")).c_str() , fontStr_kaiti, m_nFontSize); la1->addChild(la2); la2->setColor(ImageManager::getManager()->getShowColor(ZhuangbeiColour_Chuanqi, false, false)); la2->setPosition(ccp(la1->getContentSize().width+la2->getContentSize().width/2, la1->getContentSize().height/2)); la1->setPositionX((mBg->getContentSize().width-la1->getContentSize().width-la2->getContentSize().width)/2); }
bool LoginLayer::init() { if ( !BaseLayer::init() ) return false; setTouchEnabled(true); CCSize visibleSize = CCDirector::sharedDirector()->getWinSize(); addContentWithJsonFile("UI4Login.ExportJson"); _msg = static_cast<Label*>(getWidgetByName("Label_msg")); _list = static_cast<ListView*>(getWidgetByName("ListView_list")); CCSize size = CCSize(450, 85); _account = CCEditBox::create(size,CCScale9Sprite::createWithSpriteFrameName("input_login.png")); _password = CCEditBox::create(size,CCScale9Sprite::createWithSpriteFrameName("input_login.png")); _account->setPosition(ccp(visibleSize.width/2,visibleSize.height/2 + 68)); _password->setPosition(ccp(_account->getPositionX(),_account->getPositionY()-105)); ccColor3B color = {147,140,115}; _account->setFont("TrebuchetMS-Bold",30); _account->setFontColor(color); _account->setPlaceholderFontColor(color); _account->setPlaceHolder("联众账号"); _account->setMaxLength(19); _account->setSelected(true); _account->setReturnType(kKeyboardReturnTypeDone); _password->setFont("TrebuchetMS-Bold",30); _password->setFontColor(color); _password->setPlaceholderFontColor(color); _password->setPlaceHolder("密码"); _password->setMaxLength(15); _password->setInputFlag(kEditBoxInputFlagPassword); _password->setInputMode(kEditBoxInputModeSingleLine); _password->setZOrder(-1); _uilayer->addChild(_account); _uilayer->addChild(_password); _up = Button::create(); _down = Button::create(); _up->loadTextures("button_up.png", "", "",UI_TEX_TYPE_PLIST); _down->loadTextures("button_down.png", "", "",UI_TEX_TYPE_PLIST); CCPoint point = ccp(_account->getContentSize().width - 40, _account->getContentSize().height/2); _up->setPosition(point); _down->setPosition(point); UILayer* layer = UILayer::create(); layer->addWidget(_down); layer->addWidget(_up); _account->addChild(layer); _list->setAnchorPoint(ccp(0, 1)); _list->setItemModel(GUIReader::shareReader()->widgetFromJsonFile("UI4ItemAccount.ExportJson")); _list->addEventListenerListView(this, listvieweventselector(LoginLayer::onListViewEvent)); bindTouchEvent("btn_login", this, toucheventselector(LoginLayer::onClickedLogin)); bindTouchEvent("btn_register", this, toucheventselector(LoginLayer::onClickedRegister)); _up->addTouchEventListener(this, toucheventselector(LoginLayer::onClickedUp)); _down->addTouchEventListener(this, toucheventselector(LoginLayer::onClickedDown)); setAccountAndPwd(); UserAccountService userAccountService; userAccountService.createTable(); toggleAccouts(false); return true; }
bool ConfigView::init(){ if ( !CCLayer::init() ) { return false; } //初次进入 获取 其它用户或者自己的 信息 isOtherUser = Logic::getInstance()->getLookOther(); if (isOtherUser) { Logic::getInstance()->fetchInfoState = 0; } getYet = false; CCSize size = CCDirector::sharedDirector()->getVisibleSize(); CCLog("winSize %f %f", size.width, size.height); UILayer *lay = UILayer::create(); addChild(lay); //lay->setPosition(ccp(size.width/2, size.height/2)); //lay->setContentSize(size); w = GUIReader::shareReader()->widgetFromJsonFile("gui/ballUI_7_0.json"); lay->addWidget(w); w->setSize(size); Button *head = static_cast<Button*>(UIHelper::seekWidgetByName(w, "head")); head->setVisible(false); Button *back = static_cast<Button*>(UIHelper::seekWidgetByName(w, "back")); back->addTouchEventListener(this, toucheventselector(ConfigView::onBack)); Button *loginOut = static_cast<Button*>(UIHelper::seekWidgetByName(w, "quit")); loginOut->addTouchEventListener(this, toucheventselector(ConfigView::onQuit)); if (isOtherUser) { loginOut->setEnabled(false); } if (isOtherUser) { TextField *team = static_cast<TextField*>(UIHelper::seekWidgetByName(w, "team")); team->setTouchEnabled(false); team->setVisible(false); Label *tuijian = static_cast<Label*>(UIHelper::seekWidgetByName(w, "Label_22_0_1_2")); tuijian->setEnabled(false); ImageView *div = static_cast<ImageView*>(UIHelper::seekWidgetByName(w, "div_0_1_2")); div->setEnabled(false); } if (isOtherUser) { TextField *nn = static_cast<TextField*>(UIHelper::seekWidgetByName(w, "nickname")); nn->setTouchEnabled(false); Label *nicheng = static_cast<Label*>(UIHelper::seekWidgetByName(w, "Label_22_0_1")); nicheng->setText("推荐人"); TextField *account = static_cast<TextField*>(UIHelper::seekWidgetByName(w, "account")); account->setTouchEnabled(false); } scheduleUpdate(); return true; }
bool WorldCup::init(){ if ( !CCLayer::init() ) { return false; } showYet = false; inUpdateData = false; oldOrNew = 0; lastRefreshTime = 0; inRefresh = false; lastUpdateIndex = 0; dict = CCDictionary::create(); dict->retain(); CCSize size = CCDirector::sharedDirector()->getVisibleSize(); CCLog("winSize %f %f", size.width, size.height); UILayer *lay = UILayer::create(); addChild(lay); //lay->setPosition(ccp(size.width/2, size.height/2)); //lay->setContentSize(size); //w = GUIReader::shareReader()->widgetFromJsonFile("gui/ballUI_1.json"); w = GUIReader::shareReader()->widgetFromJsonFile("gui/ballUI_1_0.json"); lay->addWidget(w); CCSize rs = w->getSize(); CCLog("rootSize %f %f", rs.width, rs.height); w->setSizeType(SIZE_ABSOLUTE); w->setSize(size); Button *conf = static_cast<Button*>(UIHelper::seekWidgetByName(w, "selfinfo")); conf->addTouchEventListener(this, toucheventselector(WorldCup::onConf)); /* */ /* Button *fri = static_cast<Button*>(UIHelper::seekWidgetByName(w, "Button_5")); fri->addTouchEventListener(this, toucheventselector(WorldCup::onFri)); */ lv = static_cast<UIListView*>(UIHelper::seekWidgetByName(w, "listView")); lv->addEventListenerListView(this, listvieweventselector(WorldCup::onListview)); lv->addEventListenerScrollView(this, scrollvieweventselector(WorldCup::onScroll)); UIPanel *pan = static_cast<UIPanel*>(UIHelper::seekWidgetByName(w, "dayPanel")); pan->setEnabled(false); pc = pan->clone(); pc->setVisible(true); pc->setEnabled(true); pc->retain(); dlab = static_cast<UILabel*>(UIHelper::seekWidgetByName(pc, "date")); UIPanel *cupPanel = static_cast<UIPanel*>(UIHelper::seekWidgetByName(w, "cupPanel")); cupPanel->setEnabled(false); //整个Panel 大小一样的 按钮 //Button *full = static_cast<Button*>(UIHelper::seekWidgetByName(cupPanel, "full")); //full->setVisible(false); cp = cupPanel->clone(); cp->setVisible(true); cp->setEnabled(true); cp->retain(); /* UIPanel *pan = static_cast<UIPanel*>(UIHelper::seekWidgetByName(w, "dayPanel")); UIListView *lv = static_cast<UIListView*>(UIHelper::seekWidgetByName(w, "listView")); UIWidget *pc = pan->clone(); pc->setVisible(true); lv->pushBackCustomItem(pc); UIPanel *cupPanel = static_cast<UIPanel*>(UIHelper::seekWidgetByName(w, "cupPanel")); UIWidget *cp = cupPanel->clone(); cp->setVisible(true); lv->pushBackCustomItem(cp); lv->pushBackCustomItem(pc->clone()); lv->pushBackCustomItem(cp->clone()); lv->pushBackCustomItem(cp->clone()); lv->pushBackCustomItem(cp->clone()); */ scheduleUpdate(); return true; }
void TaoZhuangInfoUI::onEnter() { CCLayer::onEnter(); CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,-2014,true); CCSize size = CCDirector::sharedDirector()->getWinSize(); //m_lNodeList.push_back(spr); ccColor4B color = {0,0,0,100}; CCLayerColor *colorLayer1 = CCLayerColor::create(color); colorLayer1->setPosition(CCPointZero); colorLayer1->setContentSize(size); addChild(colorLayer1); UILayer* uiLayer = UILayer::create(); ///auto myLayout = dynamic_cast<Layout*>(CCUIHELPER->createWidgetFromJsonFile("testUI.ExportJson")); //alpha0中使用 Widget* myLayout = GUIReader::shareReader()->widgetFromJsonFile("NewFriendAddUI_2.ExportJson"); //alpha1中使用 uiLayer->addWidget(myLayout); this->addChild(uiLayer); //CCSize size = CCDirector::sharedDirector()->getWinSize(); myLayout->ignoreAnchorPointForPosition(false); myLayout->setAnchorPoint(ccp(0.5,0.5)); myLayout->setPosition(ccp(size.width / 2,size.height / 2)); //BaseSprite* getFullPhotoOfActor() unsigned int curGroupId = getZhuangbeiGroupID(m_sProfessionid); OneSuitInfo suitInfo; if(SuitPool::getPool()->getSuitInforByZBGroupId(curGroupId, suitInfo)) { //ImageManager::getManager()-> Label *name = dynamic_cast<Label*>(myLayout->getChildByName("Name")); if (name) { name->setText(suitInfo.suit_name.c_str()); } int index = 0; for (vector<SuitPart>::iterator iter = suitInfo.parts_of_suit.begin() ; iter != suitInfo.parts_of_suit.end() ; iter++) { index ++; Label *name1 = dynamic_cast<Label*>(myLayout->getChildByName(CCString::createWithFormat("Name%d",index)->getCString())); string nameTitle = iter->zhuangbei_name.c_str(); if (iter->zhuanbei_type == ZhuangbeiType_DanshouJian || iter->zhuanbei_type == ZhuangbeiType_ShuangshouBishou || iter->zhuanbei_type == ZhuangbeiType_ShuangshouFu || iter->zhuanbei_type == ZhuangbeiType_DanshouFazhang || iter->zhuanbei_type == ZhuangbeiType_Gong || iter->zhuanbei_type == ZhuangbeiType_ShuangshouFazhang) { nameTitle += LFStrings::getValue("ZhuangBeiWuQi"); } else if (iter->zhuanbei_type == ZhuangbeiType_Faqi || iter->zhuanbei_type == ZhuangbeiType_Dunpai) { nameTitle += LFStrings::getValue("ZhuangBeiFuShou"); } else if (iter->zhuanbei_type == ZhuangbeiType_Hushenfu) { nameTitle += LFStrings::getValue("ZhuangBeiHuShenFu"); } else if (iter->zhuanbei_type == ZhuangbeiType_KuijiaZhong || iter->zhuanbei_type == ZhuangbeiType_KuijiaQin) { nameTitle += LFStrings::getValue("ZhuangBeiXiongJia"); } else { nameTitle += LFStrings::getValue("ZhuangBeiJieZhi"); } name1->setText(nameTitle.c_str()); name1->setFontName(fontStr_kaiti); } for (int i = index + 1; i <= 6; i++) { Label *name1 = dynamic_cast<Label*>(myLayout->getChildByName(CCString::createWithFormat("Name%d",i)->getCString())); name1->setVisible(false); } for (int i = 0 ; i < 5 ; i ++) { Label *name2 = dynamic_cast<Label*>(myLayout->getChildByName(CCString::createWithFormat("Label%d",i + 1)->getCString())); name2->setFontName(fontStr_kaiti); Label *name1 = dynamic_cast<Label*>(myLayout->getChildByName(CCString::createWithFormat("ZB%dNumber",i + 1)->getCString())); if (suitInfo.suit_attr[i][0].attr_type == 0) { name2->setVisible(false); name1->setVisible(false); continue; } name1->setText(GetMoFaShuXing_ByZBAttr(suitInfo.suit_attr[i][0])); name1->setFontName(fontStr_kaiti); //string nameTitle = iter->zhuangbei_name.c_str(); } } { Label *miaoShuText = dynamic_cast<Label*>(myLayout->getChildByName("Label_50")); if (miaoShuText) { miaoShuText->setFontName(fontStr_kaiti); miaoShuText->setText(getNpcMiaoShu(m_sProfessionid).c_str()); } } CCNode *node = ImageManager::getManager()->getFullPhotoOfAllShenBing(m_sProfessionid); { UIImageView *taoZhuang = dynamic_cast<UIImageView*>(myLayout->getChildByName("Image_49")); if (taoZhuang) { myLayout->addNode(node,2); node->ignoreAnchorPointForPosition(false); node->setAnchorPoint(taoZhuang->getAnchorPoint()); node->setPosition(ccp(taoZhuang->getPositionX(),taoZhuang->getPositionY() + node->getContentSize().height / 2 + 100)); taoZhuang->setVisible(false); taoZhuang->setEnabled(false); } } { Button *closeItem = dynamic_cast<Button*>(myLayout->getChildByName("CloseBtn")); if (closeItem) { //m_iCloseItem = closeItem; m_lButtonList.push_back(closeItem); closeItem->addTouchEventListener(this, toucheventselector(TaoZhuangInfoUI::clickOk)); } } }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// // 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 CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "visible.png", "visible.png", this, menu_selector(HelloWorld::btVisbleCallback)); pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + visibleSize.height - pCloseItem->getContentSize().height/2)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); // add "HelloWorld" splash screen" CCSprite* pSprite = CCSprite::create("HelloWorld.png"); // position the sprite on the center of the screen pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(pSprite, 0); /*Frame的测试*/ Widget* frame = GUIReader::shareReader()->widgetFromJsonFile("UIRes/DemoLogin.ExportJson"); UILayer* layer =UILayer::create(); layer->setScale(0.8f); //缩放比例可以随便设置 layer->addWidget(frame); this->addChild(layer); //触碰测试 layer->getWidgetByName("login_Button")->addTouchEventListener(this,toucheventselector(HelloWorld::btMenuCallBack)); layer->getWidgetByName("close_Button")->addTouchEventListener(this,toucheventselector(HelloWorld::btMenuCallBack)); layer->getWidgetByName("agree_CheckBox")->addTouchEventListener(this,toucheventselector(HelloWorld::btMenuCallBack)); layer->getWidgetByName("name_TextField")->addTouchEventListener(this,toucheventselector(HelloWorld::btMenuCallBack)); layer->getWidgetByName("password_TextField")->addTouchEventListener(this,toucheventselector(HelloWorld::btMenuCallBack)); layer->getWidgetByName("confirm_TextField")->addTouchEventListener(this,toucheventselector(HelloWorld::btMenuCallBack)); //frame初始化,可以试一下不初始化,直接layer->setVisible(false);设置窗口不可见之后,鼠标点击原本的按钮区域,看看是否有对话框出现 m_frame.setFrame(frame,(UIImageView*)layer->getWidgetByName("backageImg")); //设置触点在对话框外面时候的回调,在哪里设置对话框不可见,不可触碰 m_frame.setTouchOutOfFrameEventListener(this,TouchOutOfFrameEvent_selector(HelloWorld::touchOutOfFrameCallback)); m_frame.setFrameVisible(true); return true; }
bool ChoosePackageScene::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } setKeypadEnabled(true); CCDirector *director = CCDirector::sharedDirector(); LayoutManager *layoutManager = LayoutManager::getInstance(); CCRect visibleRect = layoutManager->getVisibleRect(); m_Background = CCSprite::create("bg_common.jpg"); m_Background->retain(); m_Background->setPosition(director->getVisibleOrigin() + director->getVisibleSize() / 2); addChild(m_Background); CCSprite *sprite = CCSprite::create("stage_select.png"); sprite->setPosition(ccp(visibleRect.origin.x + visibleRect.size.width / 2, 630)); addChild(sprite); // Create the page view int pageViewHeight = 556; int pageWidth = 336; LGPageView *pageView = LGPageView::create(); pageView->setTouchEnabled(true); pageView->setSize(CCSizeMake(visibleRect.size.width, pageViewHeight)); pageView->setPosition(CCSizeMake(visibleRect.origin.x, + visibleRect.origin.y + (visibleRect.size.height - pageViewHeight) / 2)); pageView->setPageWidth(pageWidth); pageView->setIndicatorEnable(true); StageManager *stageManager = StageManager::getInstance(); for (int i = 0; i < sizeof(PACKAGE_IMAGE) / sizeof(PACKAGE_IMAGE[0]); ++i) { Layout *layout = Layout::create(); layout->setSize(CCSizeMake(pageWidth, pageView->getSize().height)); UIImageView *imageView = UIImageView::create(); imageView->loadTexture(PACKAGE_IMAGE[i]); imageView->setPosition(ccp(layout->getRect().size.width / 2, layout->getRect().size.height / 2)); imageView->setTag(i); imageView->addReleaseEvent(this, coco_releaseselector(ChoosePackageScene::selectPackageCallback)); imageView->setTouchEnabled(true); layout->addChild(imageView); ccFontDefinition strokeTextDef; strokeTextDef.m_fontSize = 100; #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) strokeTextDef.m_fontName = "Lithograph"; #else strokeTextDef.m_fontName = "fonts/Lithograph.ttf"; #endif strokeTextDef.m_stroke.m_strokeEnabled = true; strokeTextDef.m_stroke.m_strokeColor = LayoutManager::getInstance()->DefaultStroke; strokeTextDef.m_stroke.m_strokeSize = 30; strokeTextDef.m_fontFillColor = ccWHITE; CCLabelTTF *labelStage = CCStrokeLabel::createWithFontDefinition(CCString::createWithFormat(" %d ", (i + 1))->getCString(), strokeTextDef); labelStage->setPosition(ccp(layout->getRect().size.width / 2, layout->getRect().size.height / 2)); layout->addCCNode(labelStage); strokeTextDef.m_fontSize = 40; strokeTextDef.m_stroke.m_strokeSize = 16; CCLabelTTF *labelCompletion = CCStrokeLabel::createWithFontDefinition(CCString::createWithFormat(" %d/%d ", stageManager->getCompletedStageCount(i), stageManager->getStageCount(i))->getCString(), strokeTextDef); labelCompletion->setPosition(ccp(layout->getRect().size.width / 2, layout->getRect().size.height / 2 - labelStage->getContentSize().height / 2 - labelCompletion->getContentSize().height / 2)); layout->addCCNode(labelCompletion); m_LabelCompletions->addObject(labelCompletion); pageView->addPage(layout); } UILayer *pUiLayer = UILayer::create(); pUiLayer->addWidget(pageView); addChild(pUiLayer); pUiLayer->scheduleUpdate(); CCMenuItemImage *pBack = CCMenuItemImage::create("back.png", NULL, this, menu_selector(ChoosePackageScene::backCallback)); pBack->setAnchorPoint(CCPointZero); pBack->setPosition(ccp(visibleRect.origin.x + 18, visibleRect.origin.y + 12)); CCMenu *pMenu = CCMenu::create(pBack, NULL); pMenu->setAnchorPoint(CCPointZero); pMenu->setPosition(CCPointZero); addChild(pMenu); return true; }