void CameraZoomTest::update(ccTime dt) { CCNode *sprite; CCCamera *cam; m_z += dt * 100; sprite = getChildByTag(20); cam = sprite->getCamera(); cam->setEyeXYZ(0, 0, m_z); sprite = getChildByTag(40); cam = sprite->getCamera(); cam->setEyeXYZ(0, 0, m_z); }
CCPoint HelloWorld::toolbarpos(int pos) { CCSize WinSize = CCDirector::sharedDirector()->getWinSize(); CCNode *pNode = (CCNode *)getChildByTag(TAG_TOOLBAR); CCSize nodesize = pNode->getContentSize(); if (pos == POS_IN) { return ccp(0, WinSize.height-nodesize.height); } else { return ccp(0, WinSize.height); } }
void SchedulerUpdate::removeUpdates(ccTime dt) { CCArray* children = getChildren(); CCNode* pNode; CCObject* pObject; CCARRAY_FOREACH(children, pObject) { pNode = (CCNode*)pObject; if (! pNode) { break; } pNode->unscheduleAllSelectors(); }
void HelloWorld::ShowAbout(bool bEnable) { float fduration = 0.1; CCNode *pNode = (CCNode *)getChildByTag(TAG_ABOUT); CCActionInterval* action = NULL; if (bEnable) { action = CCMoveTo::create(fduration, aboutpos(POS_IN)); } else { action = CCMoveTo::create(fduration, aboutpos(POS_OUT)); } pNode->runAction(action); }
void MainMenu::update(float dt) { CCLayer::update(dt); CCPoint bgVel = ccp(-1000,0); bgSpace->setPosition( ccpAdd(bgSpace->getPosition(), ccpMult(bgVel,dt)) ); CCArray* bgs = CCArray::create(stars1,stars2,NULL); CCObject* obj = NULL; CCARRAY_FOREACH(bgs,obj) { CCNode* node = (CCNode*)obj; if(bgSpace->convertToWorldSpace(node->getPosition()).x < -node->getContentSize().width/2) { bgSpace->incrementOffset(ccp(2*node->getContentSize().width,0),node); } }
bool ArmatureActionState::init() { do { CCNode *pNode = SceneReader::sharedSceneReader()->getNodeByTag(_nTag); CC_BREAK_IF(pNode == NULL); CCComRender *pRender = (CCComRender*)(pNode->getComponent(_ComName.c_str())); CC_BREAK_IF(pRender == NULL); CCArmature *pAr = (CCArmature *)(pRender->getNode()); CC_BREAK_IF(pAr == NULL); TriggerMng::sharedTriggerMng()->addArmatureMovementCallBack(pAr, this, movementEvent_selector(ArmatureActionState::animationEvent)); } while (0); return true; }
void GUISpinView::refresh() { m_mainNode->removeAllChildren(); m_itemCount = m_delegate->itemsCountForSpinView(this); for (int i = 0; i < m_itemCount; i++) { CCNode * node = m_delegate->createItemForSpinView(this, i); m_mainNode->addChild(node, 0, i); node->setAnchorPoint(ccp(0, 0.5f)); CCPoint p = ccp(0, - m_itemHeight * i); if (p.y + m_itemHeight * 0.5f < - m_viewFrame.size.height * 0.5f) { p.y = m_itemHeight * (m_itemCount - i); } node->setPosition(p); } }
void GamePhysicsContactListener::BeginContact(b2Contact* contact) { // 衝突した双方の物体を取得 b2Body* bodyA = contact->GetFixtureA()->GetBody(); b2Body* bodyB = contact->GetFixtureB()->GetBody(); CCNode* nodeA = (CCNode*)bodyA->GetUserData(); CCNode* nodeB = (CCNode*)bodyB->GetUserData(); if( nodeA != NULL && nodeB != NULL ){ // if( nodeA->getTag() == NODE_TAG_BALL ){ Ball* pBall = (Ball*)nodeA; pBall->contactWith(nodeB); } else if( nodeB->getTag() == NODE_TAG_BALL ){ Ball* pBall = (Ball*)nodeB; pBall->contactWith(nodeA); } } #if 0 // 物体にひもづくSpriteを取得 PhysicsSprite* spriteA = (PhysicsSprite*)bodyA->GetUserData(); PhysicsSprite* spriteB = (PhysicsSprite*)bodyB->GetUserData(); // 地面との衝突は無視する if (spriteA->getTag() == Config::kTag_Ground || spriteB->getTag() == Config::kTag_Ground) { return; } // 衝突時の加速度を取得 b2Vec2 velocityA = bodyA->GetLinearVelocity(); b2Vec2 velocityB = bodyB->GetLinearVelocity(); CCLOG("[BeginContact] A(%f, %f) B(%f, %f)", velocityA.x, velocityA.y, velocityB.x, velocityB.y); // 加速度が一定上の大きさだったら、ぶつかられた方を削除する float threshold = 3; if (pow(velocityA.x, 2) + pow(velocityA.y, 2) > pow(threshold, 2)) { spriteB->setDeleteFlag(true); } if (pow(velocityB.x, 2) + pow(velocityB.y, 2) > pow(threshold, 2)) { spriteA->setDeleteFlag(true); } #endif }
void MultiPriceMatch::btnPriceCallback(Ref* pSender, ui::Widget::TouchEventType eEventType){ /*if (eEventType != ui::Widget::TouchEventType::BEGAN)*/ CCNode* node = (CCNode*) pSender; int tag = node->getTag(); bool bSel = false; for (int i = 0; i < 3;i++){ if (tag == (BTN_PRICE_1 + i)) bSel = true; } if (bSel == false) return; cocos2d::log("button's tag is %d",tag); auto button = (Button*) _SORT_UINode->getChildByTag(tag); AppDelegate *app = (AppDelegate*)Application::getInstance(); switch (eEventType) { case ui::Widget::TouchEventType::BEGAN: cocos2d::log("btnPriceCallback Began"); button->getTouchBeganPosition(); button->setZOrder(99); break; case ui::Widget::TouchEventType::ENDED: cocos2d::log("btnPriceCallback Ended"); if (app->getBGMstatus() == BGMusic_flag::ON){ app->PlayEffect(SOUND_BUTTON_CLICK); } button->setZOrder(1); MovetoPriceLabel(button); break; case ui::Widget::TouchEventType::MOVED: button->setPosition(button->getTouchMovePosition()); cocos2d::log("btnPriceCallback Moving"); break; case ui::Widget::TouchEventType::CANCELED: cocos2d::log("touch Cancel"); button->setZOrder(1); break; default: cocos2d::log("touch Default"); break; } return; }
bool T27ActionMore::init() { BaseLayer::init(); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCNode* c = CCNode::create(); _c = c; int actionCount = sizeof(_actionName) / sizeof(*_actionName); for (int i = 0; i < actionCount; i++) { /* CCSprite* bg = CCSprite::create("HelloWorld.png"); c->addChild(bg); bg->setPosition(ccp(winSize.width / 2 + i*winSize.width, winSize.height / 2)); */ CCLayerColor* layer; if (i % 2 == 0) { layer = CCLayerColor::create(ccc4(192, 192, 192, 255), winSize.width, winSize.height); } else { layer = CCLayerColor::create(ccc4(128, 128, 128, 255), winSize.width, winSize.height); } c->addChild(layer); layer->setPosition(ccp(i*winSize.width, 0)); /* 设置Title */ const char* title = _actionName[i]; CCLabelTTF* label = CCLabelTTF::create(title, "Arial", 36); layer->addChild(label); label->setPosition(ccp(winSize.width / 2, winSize.height - 80)); } CCScrollView* view = CCScrollView::create(winSize, c); view->setDirection(kCCScrollViewDirectionHorizontal); view->setContentSize(CCSize(winSize.width*actionCount, winSize.height)); addChild(view); c->setPositionX((1 - actionCount)*winSize.width); // 能触摸 setTouchEnabled(true); setTouchMode(kCCTouchesOneByOne); return true; }
void CCTextureWatcher::dovisit() { if (m_bFresh) { if (m_pTextures) { m_pTextures->removeAllObjects(); m_pTextures->release(); } CCTextureCache::sharedTextureCache()->removeUnusedTextures(); m_pTextures = CCTextureCache::sharedTextureCache()->snapshotTextures(); m_nTotalPage = (m_pTextures->count() + NUM_PER_PAGE - 1) / NUM_PER_PAGE; if (m_pTextures->count() > 0) { m_bFresh = false; m_pList->reload(); } } CCNode *pParent = m_pLayer->getParent(); if (pParent) { if (pParent != CCDirector::sharedDirector()->getRunningScene()) { pParent->removeChild(m_pLayer, true); CCDirector::sharedDirector()->getRunningScene()->addChild(m_pLayer, 9998); m_bFresh = true; } } else { CCDirector::sharedDirector()->getRunningScene()->addChild(m_pLayer, 9998); } pParent = m_menuHide->getParent(); if (pParent) { if (pParent != CCDirector::sharedDirector()->getRunningScene()) { pParent->removeChild(m_menuHide, true); CCDirector::sharedDirector()->getRunningScene()->addChild(m_menuHide, 9999); } } else { CCDirector::sharedDirector()->getRunningScene()->addChild(m_menuHide, 9999); } }
void CCNode::visit() { // quick return if not visible. children won't be drawn. if (!m_bVisible) { return; } // kmGLPushMatrix(); CCNode* pNode = NULL; unsigned int i = 0; if(m_Children.size() > 0) { sortAllChildren(); // draw children zOrder < 0 for( ; i < m_Children.size(); i++ ) { pNode = (CCNode*) m_Children[i]; if ( pNode && pNode->m_nZOrder < 0 ) { pNode->visit(); } else { break; } } // self draw this->draw(); for( ; i < m_Children.size(); i++ ) { pNode = (CCNode*) m_Children[i]; if (pNode) { pNode->visit(); } } } else { this->draw(); } //kmGLPopMatrix(); }
void setScrollNode(CCNode *n){ if(_scrollNode){ _scrollNode->removeAllChildrenWithCleanup(true);} _scrollNode = n; if(n){ addChild(n, 255); } }
bool CPKDlg::init() { CCLayer::init(); m_pLeftPhoto = m_pRightPhoto = NULL ; m_pDelegate = NULL ; CCNodeLoaderLibrary* plib = CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary(); CCBReader* pReader = new CCBReader(plib); CCNode* pnode = pReader->readNodeGraphFromFile("PkDlg.ccbi",this); pnode->setPosition(ccpMult(ccpFromSize(getContentSize()), 0.5)) ; addChild(pnode) ; m_pAnimate = pReader->getAnimationManager() ; m_pAnimate->setDelegate(this); pReader->autorelease() ; return true ; }
CCPoint HelloWorld::aboutpos(int pos) { CCSize WinSize = CCDirector::sharedDirector()->getWinSize(); CCNode *pNode = (CCNode *)getChildByTag(TAG_ABOUT); CCSize nodesize = pNode->getContentSize(); if (pos == POS_IN) { return ccp((WinSize.width-nodesize.width)/2, (WinSize.height-nodesize.height)/2); } else { return ccp(WinSize.width, (WinSize.height-nodesize.height)/2); } }
void GamePan::update(float delta) { CCNode* pBaseNode = m_pCcbNode->getChildByTag(kTagGamePanWordPan); CCNode* tabNode = pBaseNode->getChildByTag(kTagGamePanWordPanTabBase); CCNode* itemNode = pBaseNode->getChildByTag(kTagGamePanWordPanItemBase); vector<string> arr = Utils::split(_answerStr); string answer; for(int i = 0 ;i <arr.size();i++) { int id = atoi((arr.at(i).c_str())); CCLabelTTF* text = dynamic_cast<CCLabelTTF*>(itemNode->getChildByTag(id)); answer += text->getString(); } //CCLog(("############### "+answer).c_str()); }
bool SectorScene::init() { CCSize size = CCDirector::sharedDirector()->getWinSize(); this->setPosition(ccp(size.width/2,size.height/2)); // SectorLayer* pLayer = SectorLayer::create(); // this->addChild(pLayer); //由于处理旋转,作此修改 CCNode* node = CCNode::create(); node->addChild(SectorLayer::create()); node->runAction(RandomRotateAction::create()); this->addChild(node); return CCScene::init(); }
void BaseLevelBuilder::createMonsterBornPoints() { vector<CCPoint> points = InstanceManager::Get()->getMonsterBornPoints(); for (size_t i = 0; i < points.size(); i++) { EffectSprite* monsterBornPoint = ParticleManager::Get()->createEffectSprite(205,""); monsterBornPoint->SetAnim(kType_Play,1,true); CCNode * bornNode = CCNode::create(); bornNode->addChild(monsterBornPoint); bornNode->setPosition(points[i]); m_level->addChild(bornNode, MAP_Z_TILE_BACKGROUND); } InstanceManager::Get()->clearMonsterBornPoints(); }
//LabelBMFont - CCLabelProtocol protocol void CCLabelBMFont::setString(const char *newString) { m_sString.clear(); m_sString = newString; if (m_pChildren && m_pChildren->count() != 0) { CCObject* child; CCARRAY_FOREACH(m_pChildren, child) { CCNode* pNode = (CCNode*) child; if (pNode) { pNode->setIsVisible(false); } }
void CChangeHeadImg::addGridCell(unsigned int uIdx, CGridViewCell* pCell) { CLayout *lay = UICloneMgr::cloneLayout(m_cell); for (int i=1; i<=2; i++) { CCNode *child = lay->getChildByTag(i); lay->removeChild(child); pCell->addChild(child); if (i==1) { if (m_headIconList.at(uIdx)>0) { CImageView* pHead = CImageView::create(CCString::createWithFormat("headImg/%d.png", m_headIconList.at(uIdx))->getCString()); if(!pHead) { pHead = CImageView::create("headImg/null.png"); CCLOG("ERROR_____CChangeHeadImg::addGridCell"); } child->addChild(pHead); NodeFillParent(pHead); } else { UserData *data = DataCenter::sharedData()->getUser()->getUserData(); string fbName = data->getFbId() +".jpg"; string fullName = CCFileUtils::sharedFileUtils()->fullPathForFilename(fbName.c_str()); bool isFileExist = CCFileUtils::sharedFileUtils()->isFileExist(fullName); if(isFileExist) { CCSprite* spr =CCSprite::create(fullName.c_str()); child->addChild(spr); NodeFillParent(spr); } } } else if(i==2) { CImageView* pBtn = (CImageView*)child; pBtn->setTouchEnabled(true); pBtn->setUserData(&m_headIconList.at(uIdx)); pBtn->setOnClickListener(this,ccw_click_selector(CChangeHeadImg::onChangHeadImg)); } } }
void GameRankLayer::initTabs() { // Friend Tab CCScale9Sprite* ptrTabFriendsSelected = GameUtils::createScale9("new_blue_bg.png", CCRectMake(0,0,200,82),CCRectMake(35,35,125,10)); ptrTabFriendsSelected->setContentSize(CCSizeMake(204,82)); CCScale9Sprite* ptrTabFriendsDisabled = GameUtils::createScale9("new_blue_bg.png", CCRectMake(0,0,200,82),CCRectMake(35,35,125,10)); ptrTabFriendsDisabled->setContentSize(CCSizeMake(204,82)); CCNode* ptrTabFriendsNormal = CCNode::create(); ptrTabFriendsNormal->setContentSize(ptrTabFriendsSelected->getContentSize()); m_ptrTabFriends = CCMenuItemSprite::create(ptrTabFriendsNormal, ptrTabFriendsSelected, ptrTabFriendsDisabled, this, menu_selector(GameRankLayer::tabFriendsCallback)); m_ptrBg->addChild(m_ptrTabFriends); LayoutUtil::layoutParentLeftTop(m_ptrTabFriends, -5, -27); registerMenuItem(m_ptrTabFriends); m_ptrLbFriends = CCLabelBMFont::create(LOCALIZED_STRING("word_friends"), FontConstant::BMFONT_GOTHIC725_BLK_BT_BLUE); m_ptrLbFriends->setScale(0.6f); m_ptrTabFriends->addChild(m_ptrLbFriends); LayoutUtil::layoutParentBottom(m_ptrLbFriends,6,22); // Global Tab CCScale9Sprite* ptrTabGlobalSelected = GameUtils::createScale9("new_blue_bg.png", CCRectMake(0,0,200,82),CCRectMake(35,35,125,10)); ptrTabGlobalSelected->setContentSize(CCSizeMake(204,82)); CCScale9Sprite* ptrTabGlobalDisabled = GameUtils::createScale9("new_blue_bg.png", CCRectMake(0,0,200,82),CCRectMake(35,35,125,10)); ptrTabGlobalDisabled->setContentSize(CCSizeMake(204,82)); CCNode* ptrTabGlobalNormal = CCNode::create(); ptrTabGlobalNormal->setContentSize(ptrTabGlobalSelected->getContentSize()); m_ptrTabGolbal = CCMenuItemSprite::create(ptrTabGlobalNormal, ptrTabGlobalSelected, ptrTabGlobalDisabled,this, menu_selector(GameRankLayer::tabGlobalCallback)); m_ptrBg->addChild(m_ptrTabGolbal); LayoutUtil::layoutRight(m_ptrTabGolbal,m_ptrTabFriends,-44); registerMenuItem(m_ptrTabGolbal); m_ptrLbGlobal = CCLabelBMFont::create(LOCALIZED_STRING("word_global"), FontConstant::BMFONT_GOTHIC725_BLK_BT_BLUE); m_ptrLbGlobal->setScale(0.6f); m_ptrTabGolbal->addChild(m_ptrLbGlobal); LayoutUtil::layoutParentBottom(m_ptrLbGlobal,5,22); tabFriendsCallback(NULL); }
void CCEDEVUpgradeScene::update(float v) { CCEScene::update(v); CCEUpgradeManager* m = CCEUpgradeManager::sharedUpgradeManager(); UpgradeInfo info; m->queryInfo(&info); if(m_lastInfo.end==info.end && m_lastInfo.fail==info.fail && m_lastInfo.finishWork==info.finishWork && m_lastInfo.message.compare(info.message)==0 && m_lastInfo.totalWork==info.totalWork) { return; } CCNode* layer = getChildByTag(1); CCLabelTTF* l1 = (CCLabelTTF*) layer->getChildByTag(1); CCLabelTTF* l2 = (CCLabelTTF*) layer->getChildByTag(2); std::string s1; if(m->isProcessing() || info.end) { s1 = StringUtil::format("Status: %s", info.end?(info.fail?"fail":"done"):"processing"); if(info.message.size()>0) { s1 += " - "; s1 += info.message; } } else { s1 = "Status: not start"; } l1->setString(s1.c_str()); std::string s2; if(!m->isProcessing() || info.totalWork==0) { s2 = "Progress: -- "; } else { s2 = StringUtil::format("Progress: %2.2f", info.finishWork*100.0f/info.totalWork); } l2->setString(s2.c_str()); m_lastInfo.end = info.end; m_lastInfo.fail = info.fail; m_lastInfo.finishWork = info.finishWork; m_lastInfo.totalWork = info.totalWork; m_lastInfo.message = info.message; }
void GameScene::ccTouchEnded(CCTouch* pTouch, CCEvent* pEvent) { CCLOG("ccTouchEnded"); if (currentTag != 0) { background->removeChildByTag(tmpCurrentTag); CCNode* current = background->getChildByTag(currentTag); current->setVisible(true); background->reorderChild(current, kZOrderBlock); prependRemoveBlocks(); removeBlockAnimation(); } currentTag = 0; previousTag = 0; }
void MapMenu1Layer::gameCB( CCObject* pObject ) { CCNode *node = (CCNode*)pObject; int tag = node->getTag(); switch (tag) { case 1: loadCCBFile(1); break; case 2: CCLOG("no yet finished!!"); break; default: break; } }
/** * 键盘将要出现的时候 */ void LoginView::keyboardWillShow(CCIMEKeyboardNotificationInfo& info) { CCLog("LoginView:keyboardWillShowAt(origin:%f,%f, size:%f,%f)", info.end.origin.x, info.end.origin.y, info.end.size.width, info.end.size.height); if (! this->mTrackNodeArray) { return; } CCNode* trackNode = NULL ; CCRect rectTracked ; for(int i=0; i<this->mTrackNodeArray->count(); i++) { trackNode = (CCNode*) this->mTrackNodeArray->objectAtIndex(i) ; rectTracked = getRect(trackNode); CCLog("LoginView:trackingNodeAt(origin:%f,%f, size:%f,%f)", rectTracked.origin.x, rectTracked.origin.y, rectTracked.size.width, rectTracked.size.height); // if the keyboard area doesn't intersect with the tracking node area, nothing need to do. if (! CCRect::CCRectIntersectsRect(rectTracked, info.end)) { continue ; } // assume keyboard at the bottom of screen, calculate the vertical adjustment. float adjustVert = info.end.getMaxY() - rectTracked.getMinY(); CCLog("LoginView:needAdjustVerticalPosition(%f)", adjustVert); // move all the children node of KeyboardNotificationLayer CCArray* children = getChildren(); CCNode* node = 0; int count = children->count(); CCPoint pos; for (int i = 0; i < count; ++i) { node = (CCNode*)children->objectAtIndex(i); pos = node->getPosition(); pos.y += adjustVert; node->setPosition(pos); } } }
void GameMenuScene::onEnter(){ CCLayer::onEnter(); CCSize size = CCDirector::sharedDirector()->getWinSize(); CCNode* mainmenu = this->getChildByTag(3); mainmenu->setPositionX(-200); mainmenu->runAction(CCSequence::create( //CCEaseElasticIn::create (CCMoveTo::create(0.5,ccp(0,0))), CCCallFuncN::create(this->getChildByTag(3), callfuncN_selector(GameMenuScene::menuEnter) ) , NULL)); }
void ParallaxBackground::Scroll(CCTouch* touch) { CCPoint diff = touch->getDelta(); CCNode* node = getChildByTag(0); CCPoint currentPos = node->getPosition(); float xpos = currentPos.x + diff.x; float ypos = currentPos.y/* + diff.y*/; ypos = std::max(ypos, -35.f); ypos = std::min(ypos, 35.f); xpos = std::max(xpos, -50.f); xpos = std::min(xpos, 50.f); node->setPosition(xpos , ypos ); }
void TapSprite::eraseSoldierMap(int x,int y){ status->setEraseFlg(combo, x, y); // 削除対象ノードにペアレントが存在する場合は切り離して捨てる CCNode* parent; CCSprite* sprite; sprite = status->getSprite(x,y); if(!sprite) return; parent = sprite->getParent(); if(!parent) return; parent->removeChild(sprite); status->setSprite(NULL, x, y); }
void HallPage::onAddFriendClicked() { if(m_sendGiftDialog != 0){ m_sendGiftDialog->destroy(); m_sendGiftDialog = 0; } CCNode *root = this->getParent(); while(root->getParent()) root = root->getParent(); if(m_addFriendDialog == 0){ m_addFriendDialog = new AddFriendDialog(root,ccc4(0,0,0,128)); m_addFriendDialog->setCloseCB(this,callfuncND_selector(HallPage::onAddFriendCloseClicked)); m_addFriendDialog->setAddCB(this,callfuncND_selector(HallPage::onAddFriendAddClicked)); m_addFriendDialog->setAddId(m_headId); m_addFriendDialog->exec(); } }
CCPoint HelloWorld::titlepos(int pos) { CCSize WinSize = CCDirector::sharedDirector()->getWinSize(); CCNode *pNode = (CCNode *)getChildByTag(TAG_TITLE); CCSize nodesize = pNode->getContentSize(); if (pos == POS_IN) { return ccp(WinSize.width/2, WinSize.height/2+nodesize.height); } else { return ccp(-nodesize.width/2, WinSize.height/2+nodesize.height); } }