cocos2d::FiniteTimeAction* cce::CCEChannel::getSplineActions(){ int frameCount = this->keyframes.size(); if(frameCount==0){ return NULL; } CCPointArray * array = CCPointArray::create(frameCount); int startIndex,endIndex; ActionMoveFrame *lastFrame; for (int i = 0; i < frameCount; i++) { ActionMoveFrame *frame = (ActionMoveFrame *)this->keyframes.at(i); array->addControlPoint(frame->getPosition()); if(i==0){ startIndex = frame->getFrameIndex(); } if(i==(frameCount-1)){ endIndex=frame->getFrameIndex(); lastFrame=frame; } } float duration = (endIndex-startIndex) * getUnitTime(); cocos2d::FiniteTimeAction *action=NULL; if(type=="SplineTo"){ action= CCCardinalSplineTo::create(duration, array,0); }else if(type=="SplineBy"){ action=CCCardinalSplineBy::create(duration, array,0); } if(startIndex>0){ action = CCSequence::create(CCDelayTime::create(startIndex*getUnitTime()),action,nullptr); } return lastFrame->getEasingAction(action); }
void MainScene::PushFlyingBubbles(const MatchesList_t& bubbles) { size_t size = bubbles.size(); for (size_t i = 0; i < size; ++i) { CCPointArray *array = CCPointArray::create(20); int x = m_BubbleViewDisplacement.x + bubbles[i].y * (BubbleElement::GetBubbleSize() + m_SpaceBetweenBubbles); int y = VisibleRect::top().y - m_BubbleViewDisplacement.y - BubbleElement::GetBubbleSize() - bubbles[i].x * (BubbleElement::GetBubbleSize() + m_SpaceBetweenBubbles); array->addControlPoint(ccp(x, y)); array->addControlPoint(ccp(x + 30, y + 30)); array->addControlPoint(ccp(x + 60, y + 50)); array->addControlPoint(ccp(x + 80, y + 70)); array->addControlPoint(ccp(750, 400)); CCCardinalSplineTo *action = CCCardinalSplineTo::create(1.5, array, 0); CCFiniteTimeAction* actionMoveDone = CCCallFuncN::create( this, callfuncN_selector(MainScene::RemoveFlyingBubbles)); CCFiniteTimeAction *seq = CCSequence::create(action, actionMoveDone, NULL); BubbleElement* bubble = new BubbleElement(static_cast<BubbleElement*>(m_BubblesView[bubbles[i].y][bubbles[i].x])->GetType()); bubble->setPosition(CCPointMake(x, y)); bubble->runAction(seq); addChild(bubble); } }
void PlayLayer::playBeanAnimation(CCSprite* sprite,int row,int column,bool left) { CCLOG("error row = %d column = %d",row,column); ccBezierConfig bezier; int startX = sprite->getPosition().x; int startY = sprite->getPosition().y; int endX =0; int endY = -1*GAME_BLOCK_HEIGHT; if(left) { endX = -1 * rand()%120 - 50 + startX; } else { endX = rand()%120 + 50 + startX; } CCPointArray * array = CCPointArray::create(20); array->addControlPoint(ccp(startX,startY)); array->addControlPoint(ccp((endX - startX)/2 + startX,startY + rand()%20 + 10)); array->addControlPoint(ccp(endX,endY)); float time = 1.5*row/GAME_BLOCK_ROW_NUMBER; if(time >= 1) { time = 1; } if(time < 0.5) { time = 0.5; } CCActionInterval * CardinalSplineTo=CCCardinalSplineTo::create(time, array, 0); CCActionInterval *sequence = CCSequence::create(CardinalSplineTo,CCCallFuncND::create(this,callfuncND_selector(PlayLayer::spriteCallBack),(void*)sprite),NULL); sprite->runAction(sequence); }
ToyBrick* DancingBoneLayer::CreateArm() { //image && texture char path[255]; sprintf(path, "Images/DancingBone/arm.png"); CCImage *img = new CCImage(); img->autorelease(); if (!img->initWithImageFile(path, CCImage::kFmtPng)) { return NULL; } CCTexture2D *texture = new CCTexture2D(); texture->autorelease(); if (!texture->initWithImage(img)) { return NULL; } // ToyBrick *brick = ToyBrick::create(); CCSize size = texture->getContentSize(); brick->Init(texture, CCRectMake(0, 0, size.width, size.height)); //vector (24, 102) CCPointArray *vector = CCPointArray::create(4); vector->addControlPoint(ccp(-12, -50)); vector->addControlPoint(ccp(12, -50)); vector->addControlPoint(ccp(12, 50)); vector->addControlPoint(ccp(-12, 50)); brick->SetAsPolygon(vector); return brick; }
void HPDPS::effectIncreaseHP() { float f = 300; float x = 350; float y = 300; static int t = 0; t++; if(t <= 5) { CCSprite *increase = CCSprite::create("heart.png"); increase->setPosition(ccp(x - f/2, y+f*2/3+9)); Attacker::sharedAttacker()->addChild(increase); increase->setColor(ccc3(255, 0, 0)); increase->setTag(t); CCPointArray *array = CCPointArray::create(20); array->addControlPoint(ccp(x-f/2, y +f*2/3+9)); array->addControlPoint(ccp(x - f*7/6-6, y + f/3+6)); array->addControlPoint(ccp(x - f*3/2-9, y-f/3)); array->addControlPoint(ccp(x - f*7/6-6, y - f-6)); array->addControlPoint(ccp(x-f/2, y-f*4/3-9)); array->addControlPoint(ccp(x + f/6+6, y - f-6)); array->addControlPoint(ccp(x + f/2+9, y-f/3)); array->addControlPoint(ccp(x + f/6+6, y + f/3+6)); array->addControlPoint(ccp(x-f/2, y + f*2/3+9)); CCCardinalSplineTo *spline = CCCardinalSplineTo::create(1.5, array, 0); increase->runAction(spline); switch (t) { case 1: scheduleOnce(schedule_selector(HPDPS::remove1), 1.5f); break; case 2: scheduleOnce(schedule_selector(HPDPS::remove2), 1.5f); break; case 3: scheduleOnce(schedule_selector(HPDPS::remove3), 1.5f); break; case 4: scheduleOnce(schedule_selector(HPDPS::remove4), 1.5f); break; case 5: scheduleOnce(schedule_selector(HPDPS::remove5), 1.5f); break; default: break; } if(t == 5) { t = 0; unschedule(schedule_selector(HPDPS::effectIncreaseHP)); } } }
CCObject* CCPointArray::copyWithZone(cocos2d::CCZone *zone) { CCArray *newArray = (CCArray*)m_pControlPoints->copy(); CCPointArray *points = CCPointArray::create(10); points->retain(); points->setControlPoints(newArray); newArray->release(); return points; }
CCPointArray* CCPointArray::reverse() { CCArray *newArray = new CCArray(m_pControlPoints->count()); for (int i = m_pControlPoints->count()-1; i >= 0; --i) { newArray->addObject(m_pControlPoints->objectAtIndex(i)); } CCPointArray *config = CCPointArray::create(0); config->setControlPoints(newArray); newArray->release(); return config; }
CCPointArray* IOSStoreLayer::randStarPoint(int iCount) { CCPointArray* pointRet = CCPointArray::create(iCount); pointRet->addControlPoint(ccp(60, 210)); pointRet->addControlPoint(ccp(80, 330)); pointRet->addControlPoint(ccp(115, 450)); pointRet->addControlPoint(ccp(270, 570)); pointRet->addControlPoint(ccp(230, 100)); pointRet->addControlPoint(ccp(425, 550)); pointRet->addControlPoint(ccp(550, 410)); pointRet->addControlPoint(ccp(540, 180)); return pointRet; }
CCPointArray* CCPointArray::reverse() { vector<CCPoint*> *newArray = new vector<CCPoint*>(); vector<CCPoint*>::reverse_iterator iter; CCPoint *point = NULL; for (iter = m_pPoints->rbegin(); iter != m_pPoints->rend(); ++iter) { point = *iter; newArray->push_back(new CCPoint(point->x, point->y)); } CCPointArray *config = CCPointArray::create(0); config->setPoints(newArray); return config; }
CCObject* CCPointArray::copyWithZone(cocos2d::CCZone *zone) { vector<CCPoint*> *newArray = new vector<CCPoint*>(); vector<CCPoint*>::iterator iter; for (iter = m_pPoints->begin(); iter != m_pPoints->end(); ++iter) { newArray->push_back(new CCPoint((*iter)->x, (*iter)->y)); } CCPointArray *points = new CCPointArray(); points->initWithCapacity(10); points->setPoints(newArray); return points; }
void CCCatmullRomSprite::setControlPoints(CCPointArray& pa) { m_controlPoints.clear(); const vector<CCPoint*>* plist = pa.getControlPoints(); for(vector<CCPoint*>::const_iterator iter = plist->begin(); iter != plist->end(); iter++) { m_controlPoints.addPoint((*iter)->x, (*iter)->y); } m_dirty = true; }
CCPointArray* CCPointArray::create(unsigned int capacity) { CCPointArray* ret = new CCPointArray(); if (ret) { if (ret->initWithCapacity(capacity)) { ret->autorelease(); } else { delete ret; ret = NULL; } } return ret; }
CCPointArray* CCPointArray::create(unsigned int capacity) { CCPointArray* ret = new CCPointArray(); if (ret) { if (ret->initWithCapacity(capacity)) { CC_SAFE_AUTORELEASE(ret); } else { delete ret; ret = NULL; } } return ret; }
void IOSStoreLayer::showStarsFadeEffect(CCNode* pBox) { int iStarCount = 8; CCPointArray* pPointArray = randStarPoint(iStarCount); for (int i = 0; i < iStarCount; ++i) { CCSprite* pStar = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_storelayerPath+"daoju_baoxiang_xiaoguo_2.png").c_str()); pStar->setScale(this->randScale()); pStar->setRotation(this->randRotation()); pBox->addChild(pStar); CCPoint point = pPointArray->getControlPointAtIndex(i); pStar->setPosition(ccp(point.x , point.y)); pStar->setTag(box_star_tag); float dt = CCRANDOM_0_1() + 1.0f; float scale = CCRANDOM_0_1() + 0.5f; pStar->runAction(CCRepeatForever::create(CCSequence::create(CCFadeOut::create(dt), CCFadeIn::create(dt), NULL))); CCScaleBy* pscaleby = CCScaleBy::create(dt, scale); pStar->runAction(CCRepeatForever::create(CCSequence::create(pscaleby, pscaleby->reverse(), NULL))); } }
ToyBrick* ToyLayer::CreateBrick_Rectangle() { int num = CommonHelper::GetRandomNum(1, 20); //image && texture char path[255]; sprintf(path, "Images/ToyBrick/Rectangle/%d.png", num); CCImage *img = new CCImage(); img->autorelease(); if (!img->initWithImageFile(path, cocos2d::CCImage::kFmtPng)) { return NULL; } CCTexture2D *texture = new CCTexture2D(); texture->autorelease(); if (!texture->initWithImage(img)) { return NULL; } // ToyBrick *brick = ToyBrick::create(); CCSize size = texture->getContentSize(); brick->Init(texture, CCRectMake(0, 0, size.width, size.height)); //vector CCPointArray *vector = CCPointArray::create(4); vector->addControlPoint(ccp(-52, -52)); vector->addControlPoint(ccp(52, -52)); vector->addControlPoint(ccp(52, 52)); vector->addControlPoint(ccp(-52, 52)); brick->SetAsPolygon(vector); return brick; }
void CEnemySprite::setPosType(int posType) { CCSize screen = CCDirector::sharedDirector()->getWinSize(); CCSize enemySize = m_pSprite->getContentSize(); CCPointArray* startPosArray = CCPointArray::create(EnemyStartTypeMax); startPosArray->addControlPoint(ccp(0, 0));//EnemyStartTypeNone startPosArray->addControlPoint(ccp(screen.width / 2, screen.height + enemySize.height / 2));//1 EnemyStartTypeTop startPosArray->addControlPoint(ccp(screen.width / 3, screen.height + enemySize.height / 2));//2 EnemyStartTypeTopLeft startPosArray->addControlPoint(ccp(screen.width * 2 / 3, screen.height + enemySize.height / 2));//3 EnemyStartTypeTopRight startPosArray->addControlPoint(ccp(-enemySize.width / 2, screen.height * 2 / 3));//4 EnemyStartTypeLeft startPosArray->addControlPoint(ccp(screen.width + enemySize.width / 2, screen.height * 2 / 3));//5 EnemyStartTypeRight startPosArray->addControlPoint(ccp(-enemySize.width / 2, screen.height / 3));//6 EnemyStartTypeLeft2 startPosArray->addControlPoint(ccp(screen.width + enemySize.width / 2, screen.height / 3));//7 EnemyStartTypeRight2 m_pos = startPosArray->getControlPointAtIndex(posType); CCLog("CEnemySprite::setPosType posType: %d, pos: %0.2f, %0.2f", posType, m_pos.x, m_pos.y); m_pSprite->setPosition(m_pos); }
NS_CC_BEGIN /* * Implementation of CCPointArray */ CCPointArray* CCPointArray::create(unsigned int capacity) { CCPointArray* ret = new CCPointArray(); if (ret) { if (ret->initWithCapacity(capacity)) { ret->autorelease(); } else { delete ret; ret = NULL; } } return ret; }
void MainFooterLayer::showLiziXiaoguo(CCNode* pParent, int iTag) { //极限守城20级开启,所以效果20级才显示 //竞技8级开启,所以效果8级才显示 int iMinLevel = 8; if (iTag == TAG_Jixianshoucheng_lizi_Ani) { iMinLevel = 20; } if (!pParent || MyselfManager::getManager()->getMyZhuJueData()->getCurrentProperty().level < iMinLevel) { return; } CCNode* pNode = pParent->getChildByTag(iTag); if (pNode) { return; } CCParticleSystemQuad* par = CCParticleSystemQuad::create("jingji_xiaoguo.plist"); pParent->addChild(par, 2, iTag); //par->setScale(0.5f); //par->setSpeed(10); par->setPosition(ccp(0, 0)); CCPointArray *array = CCPointArray::create(20); array->addControlPoint(ccp(0, 0)); array->addControlPoint(ccp(pParent->getContentSize().width, 0)); array->addControlPoint(ccp(pParent->getContentSize().width, pParent->getContentSize().height)); array->addControlPoint(ccp(0, pParent->getContentSize().height)); float dt = 0.5f; CCMoveTo* action1 = CCMoveTo::create(dt, array->getControlPointAtIndex(1)); CCMoveTo* action2 = CCMoveTo::create(dt, array->getControlPointAtIndex(2)); CCMoveTo* action3 = CCMoveTo::create(dt, array->getControlPointAtIndex(3)); CCMoveTo* action4 = CCMoveTo::create(dt, array->getControlPointAtIndex(0)); CCSequence* quece = CCSequence::create(action1, action2, action3, action4, NULL); par->runAction( CCRepeatForever::create( //FXCircleBy::create(1.0f, ccp(pJingjiItem->getContentSize().width/2, pJingjiItem->getContentSize().height/2 + 5), 24, 360) quece ) ); }
CCActionInterval* CCCardinalSplineBy::reverse() { CCPointArray *copyConfig = (CCPointArray*)m_pPoints->copy(); // // convert "absolutes" to "diffs" // CCPoint p = copyConfig->getControlPointAtIndex(0); for (unsigned int i = 1; i < copyConfig->count(); ++i) { CCPoint current = copyConfig->getControlPointAtIndex(i); CCPoint diff = ccpSub(current, p); copyConfig->replaceControlPoint(diff, i); p = current; } // convert to "diffs" to "reverse absolute" CCPointArray *pReverse = copyConfig->reverse(); copyConfig->release(); // 1st element (which should be 0,0) should be here too p = pReverse->getControlPointAtIndex(pReverse->count()-1); pReverse->removeControlPointAtIndex(pReverse->count()-1); p = ccpNeg(p); pReverse->insertControlPoint(p, 0); for (unsigned int i = 1; i < pReverse->count(); ++i) { CCPoint current = pReverse->getControlPointAtIndex(i); current = ccpNeg(current); CCPoint abs = ccpAdd(current, p); pReverse->replaceControlPoint(abs, i); p = abs; } return CCCardinalSplineBy::create(m_fDuration, pReverse, m_fTension); }
void TapSprite::changeSoldier(int x, int y){ int i; if(x){ i = abs(x); }else{ i = abs(y); } int absx = 0; if(x > 0){ absx = 1; }else if (x < 0){ absx = -1; } int absy = 0; if(y > 0){ absy = 1; }else if (y < 0){ absy = -1; } int destx = thisx; int desty = thisy; for(int j = 0;j < i;j++){ if(x > 0){ destx++; }else if(x < 0){ destx--; } if(y > 0){ desty++; }else if(y < 0){ desty--; } CCSize size = this->getTexture()->getContentSize(); CCSprite* dest = status->getSprite(destx,desty); CCNode* parent; CCSprite* sprite; parent = dest->getParent(); parent->removeChild(dest); parent->addChild(dest); sprite = status->getSprite(thisx,thisy); parent = sprite->getParent(); parent->removeChild(sprite); parent->addChild(sprite); CCPointArray* pAry = CCPointArray::create(3); pAry->addControlPoint(ccp(0,0)); dest->stopAllActions(); dest->setPosition(ccp((size.width * (destx)) + size.width/2 + 5, (size.height * (desty)) + size.height/2)); if(x && y){ pAry->addControlPoint(ccp(size.width * (-absx) * 0.75f, size.height * (-absy) * 0.25f )); } else if(x){ pAry->addControlPoint(ccp(size.width * 0.5f * (-absx), -size.height * 0.5f )); } else if(y){ pAry->addControlPoint(ccp(size.width * 0.5f,size.height * 0.5f * (-absy))); } pAry->addControlPoint(ccp(size.width * (-absx),size.height * (-absy))); dest->runAction(CCCardinalSplineBy::create(0.125f, pAry,1.0f)); ((TapSprite*)dest)->setPlace(thisx,thisy); int tempStatus = status->getSoldier(destx, desty); status->setSoldier(status->getSoldier(thisx, thisy),destx, desty); status->setSoldier(tempStatus,thisx,thisy); status->setSprite(status->getSprite(thisx, thisy),destx, desty); status->setSprite(dest,thisx,thisy); thisx = destx; thisy = desty; } }
bool AllianceAreaPopupView::init(){ if(!PopupBaseView::init()){ return false; } setIsHDPanel(true); isMoving = false; this->setModelLayerOpacity(0); this->setContentSize(CCDirector::sharedDirector()->getWinSize()); m_picNode = CCNode::create(); m_picNode->setContentSize(CCSize(_tile_width * 2, _tile_height * 2)); m_picNode->setAnchorPoint(ccp(0, 0)); CCPoint testPoint =PopupViewController::getInstance()->getTouchPoint() + ccp(-_tile_width, -_tile_height); // m_picNode->setPosition(PopupViewController::getInstance()->getTouchPoint() + ccp(-_tile_width, -_tile_height)); CCPoint tilePoint = WorldController::getInstance()->getPointByIndex(m_tileIndex); CCPoint viewPoint = getInLayerPoint(tilePoint); viewPoint = viewPoint + ccp(-_tile_width * 1.5, -_tile_height); m_picNode->setPosition(viewPoint); m_cityNode = CCNode::create(); /*int mapIndex = 3; while (mapIndex >= 0) { auto arr = WorldController::getInstance()->getCityPicArr(mapIndex, 0, false ,44996); int posX = _tile_width / 2; int posY = _tile_height / 2; if(mapIndex == 0 || mapIndex == 2){ posX = _tile_width; } if(mapIndex == 3){ posX = _tile_width + posX; } if(mapIndex == 1 || mapIndex == 3){ posY = _tile_height; } if(mapIndex == 2){ posY = _tile_height + posY; } auto itMap = arr.begin(); while (itMap!=arr.end()) { std::string picName = (*itMap).pic; int addX = (*itMap).x; int addY = (*itMap).y; auto sprite = CCLoadSprite::createSprite(picName.c_str()); sprite->setAnchorPoint(ccp(0, 0)); if (CCCommonUtils::isIosAndroidPad()) { m_cityNode->addChild(sprite); sprite->setPosition(ccp(posX, posY) - ccp(_tile_width / 2, _tile_height / 2) + ccp(addX, addY)); } else { m_picNode->addChild(sprite); sprite->setPosition(ccp(posX, posY) - ccp(_tile_width / 2, _tile_height / 2) + ccp(addX, addY)); } ++itMap; } mapIndex--; }*/ auto tower = CCLoadSprite::createSprite("territory_fort.png"); tower->setPosition(ccp(_tile_width -25, _tile_height + 62)); m_picNode->addChild(tower); if (CCCommonUtils::isIosAndroidPad()) { m_picNode->addChild(m_cityNode); m_cityNode->setScale(WORLD_DEFAULT_HD_SCALE); m_cityNode->setPosition(ccp(-_tile_width * (WORLD_DEFAULT_HD_SCALE - 1),-_tile_height * (WORLD_DEFAULT_HD_SCALE - 1))); } CCPointArray* pointArr = CCPointArray::create(3); pointArr->addControlPoint(ccp(-70,59)); pointArr->addControlPoint(ccp(-2,23)); pointArr->addControlPoint(ccp(66,57)); CCLoadSprite::doResourceByCommonIndex(507, true); for (int i = 0; i < 3; i++) { auto bannerSprite = CCFlagWaveSprite::create(CCLoadSprite::loadResource("1212_double.png")); if (CCCommonUtils::isIosAndroidPad()) { bannerSprite->setScale(0.25); } else bannerSprite->setScale(0.18); bannerSprite->setPosition(ccp(_tile_width, _tile_height)+pointArr->getControlPointAtIndex(i) + ccp(12, 20)); m_picNode->addChild(bannerSprite); } CCLoadSprite::doResourceByCommonIndex(507, false); if (CCCommonUtils::isIosAndroidPad()) { m_cancelBtn = CCControlButton::create(CCLoadSprite::createScale9Sprite("but_blue.png")); m_cancelBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(AllianceAreaPopupView::onCancelBtnClick), CCControlEventTouchUpInside); m_cancelBtn->setPreferredSize(CCSize(160, 70)); m_cancelBtn->setScaleX(2.1); m_cancelBtn->setScaleY(1.7); m_confirmBtn = CCControlButton::create(CCLoadSprite::createScale9Sprite("btn_green3.png")); m_confirmBtn->setBackgroundSpriteForState(CCLoadSprite::createScale9Sprite("btn_green3.png"),CCControlStateHighlighted); m_confirmBtn->setBackgroundSpriteForState(CCLoadSprite::createScale9Sprite("Btn_grey.png"),CCControlStateDisabled); m_confirmBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(AllianceAreaPopupView::onConfirmBtnClick), CCControlEventTouchUpInside); m_confirmBtn->setPreferredSize(CCSize(160, 70)); m_confirmBtn->setScaleX(2.1); m_confirmBtn->setScaleY(1.7); auto bg = CCLoadSprite::createSprite("technology_11.png"); m_picNode->addChild(bg); m_btnLabel = CCLabelIF::create(_lang("115302").c_str()); m_btnLabel->setFontSize(32); m_btnLabel->setColor(ccc3(255, 255, 255)); m_btnLabel1 = CCLabelIF::create(_lang("115021").c_str()); m_btnLabel1->setFontSize(32); m_btnLabel1->setColor(ccc3(255, 255, 255)); m_picNode->addChild(m_cancelBtn); m_cancelBtn->setPosition(_tile_width - m_cancelBtn->getContentSize().width * m_cancelBtn->getScaleX() / 2 - 15, 0); m_picNode->addChild(m_confirmBtn); m_confirmBtn->setPosition(_tile_width + m_confirmBtn->getContentSize().width * m_confirmBtn->getScaleX() / 2 + 15, m_cancelBtn->getPositionY()); m_picNode->addChild(m_btnLabel); m_btnLabel->setPosition(m_confirmBtn->getPosition()); m_picNode->addChild(m_btnLabel1); m_btnLabel1->setPosition(m_cancelBtn->getPosition()); bg->setPosition(ccp(_tile_width, m_cancelBtn->getPositionY())); bg->setScaleY(8); bg->setScaleX(5); } else { m_cancelBtn = CCControlButton::create(CCLoadSprite::createScale9Sprite("but_blue.png")); CCCommonUtils::setButtonTitleColor(m_cancelBtn, ccc3(255, 255, 255)); CCCommonUtils::setButtonTitle(m_cancelBtn, _lang("115021").c_str()); m_cancelBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(AllianceAreaPopupView::onCancelBtnClick), CCControlEventTouchUpInside); m_cancelBtn->setPreferredSize(CCSize(160, 70)); m_confirmBtn = CCControlButton::create(CCLoadSprite::createScale9Sprite("btn_green3.png")); m_confirmBtn->setBackgroundSpriteForState(CCLoadSprite::createScale9Sprite("btn_green3.png"),CCControlStateHighlighted); m_confirmBtn->setBackgroundSpriteForState(CCLoadSprite::createScale9Sprite("Btn_grey.png"),CCControlStateDisabled); m_confirmBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(AllianceAreaPopupView::onConfirmBtnClick), CCControlEventTouchUpInside); m_confirmBtn->setPreferredSize(CCSize(160, 70)); CCCommonUtils::setButtonTitleColor(m_confirmBtn, ccc3(255, 255, 255)); CCCommonUtils::setButtonTitle(m_confirmBtn, _lang("115302").c_str()); auto bg = CCLoadSprite::createSprite("technology_11.png"); m_picNode->addChild(bg); m_iconNode = CCNode::create(); int num = WorldController::getInstance()->m_bAAreaCost; std::string picPath = ""; // picPath = "ui_gold.png"; // // // auto sprite = CCLoadSprite::createSprite(picPath.c_str()); // m_iconNode->addChild(sprite); // CCCommonUtils::setSpriteMaxSize(sprite, 40); m_numText = CCLabelIF::create(CC_ITOA(num)); // m_btnLabel = CCLabelIF::create(_lang("115302").c_str()); // m_btnLabel->setFontSize(22); // m_btnLabel->setColor(ccc3(255, 230, 116)); m_picNode->addChild(m_cancelBtn); m_cancelBtn->setPosition(_tile_width - m_cancelBtn->getContentSize().width / 2 - 15, 0); m_picNode->addChild(m_confirmBtn); m_confirmBtn->setPosition(_tile_width + m_confirmBtn->getContentSize().width / 2 + 15, m_cancelBtn->getPositionY()); // m_numBG = CCLoadSprite::createSprite("num_text_bg.png"); // m_picNode->addChild(m_numBG); // m_numBG->setScaleX(1.1); bg->setPosition(ccp(_tile_width, m_cancelBtn->getPositionY())); bg->setScaleY(4); bg->setScaleX(3); m_picNode->addChild(m_iconNode); m_iconNode->setPosition(m_confirmBtn->getPositionX() - 30, m_confirmBtn->getPositionY() - 15); // m_picNode->addChild(m_numText); // m_numText->setAnchorPoint(ccp(0, 0.5)); // m_numText->setPosition(m_confirmBtn->getPositionX(), m_confirmBtn->getPositionY() - 15); // m_picNode->addChild(m_btnLabel); // m_btnLabel->setPosition(m_confirmBtn->getPositionX(), m_confirmBtn->getPositionY() + 20); // m_numBG->setPosition(ccp(m_confirmBtn->getPositionX(), m_confirmBtn->getPositionY() - 15)); } this->addChild(m_picNode, 2); m_showNode = CCNode::create(); this->addChild(m_showNode, 1); refreshShowNode(false); return true; }
// Breakable(破壊可能)のタイルを赤にする void Game::setTileEffect(CCPoint position) { // stage and area _hud->setStageLabel(1, 1); _hud->setLifeLabel(1); CCPoint tileCoord = this->tileCoordForPosition(position); // キャラクターの上下左右の座標 CCPointArray *pointArray = CCPointArray::create(4); pointArray->addControlPoint(ccp(0,1)); pointArray->addControlPoint(ccp(-1,0)); pointArray->addControlPoint(ccp(1,0)); pointArray->addControlPoint(ccp(0,-1)); for(int i = 0; i < pointArray->count(); i++){ CCPoint point = pointArray->getControlPointAtIndex(i); //CCLog("(%f,%f)", point.x, point.y); CCPoint tmpTileCoord = ccp(tileCoord.x + point.x, tileCoord.y + point.y); if(tmpTileCoord.x < 0 || tmpTileCoord.x > _tileMap->getMapSize().width -1 || tmpTileCoord.y < 0 || tmpTileCoord.y > _tileMap->getMapSize().height - 1) { continue; } //CCLog("(%f,%f)", tmpTileCoord.x, tmpTileCoord.y); //CCLog("TileX %f, TileY %f", _tileMap->getMapSize().width, _tileMap->getMapSize().height); int tileGid = _meta->tileGIDAt(tmpTileCoord); if (tileGid) { CCDictionary *properties = _tileMap->propertiesForGID(tileGid); if (properties) { // obstacle CCString *collision = new CCString(); // Breakableを赤 *collision = *properties->valueForKey("Breakable"); if (collision && (collision->compare("True") == 0)) { CCSprite *sprite = _background->tileAt(tmpTileCoord); //sprite->setTag(TAPPABLE); // red sprite->setColor(ccRED); } } } } // 白に戻す // まず詰める /* ◯は赤なので変化させない |6,0|6,1|6,2|6,3|6,4|6,5|6,6| |5,0|5,1|5,2|5,3|5,4|5,5|5,6| |4,0|4,1|4,2|◯4,3|4,4|4,5|4,6| |3,0|3,1|◯3,2|3,3|◯3,4|3,5|3,6| |2,0|2,1|2,2|◯2,3|2,4|2,5|2,6| |1,0|1,1|1,2|1,3|1,4|1,5|1,6| |0,0|0,1|0,2|0,3|0,4|0,5|0,6| */ CCPointArray *revertPointArray = CCPointArray::create(255); for (int i = 0; i < 7; i++) { for (int j = 0; j < 7; j++) { if((i == 3 && j == 2) || (i == 3 && j == 4) || (i == 2 && j == 3) || (i == 4 && j == 3) ) { continue; } revertPointArray->addControlPoint(ccp(-3 + j, -3 + i)); } } // 詰めたものから適用 for(int i = 0; i < revertPointArray->count(); i++) { CCPoint point = revertPointArray->getControlPointAtIndex(i); //CCLog("(%f,%f)", point.x, point.y); CCPoint tmpTileCoord = ccp(tileCoord.x + point.x, tileCoord.y + point.y); // 画面端はエラーになるので適用させない if(tmpTileCoord.x < 0 || tmpTileCoord.x > _tileMap->getMapSize().width - 1|| tmpTileCoord.y < 0 || tmpTileCoord.y > _tileMap->getMapSize().height - 1) { continue; } //CCLog("(%f,%f)", tmpTileCoord.x, tmpTileCoord.y); int tileGid = _meta->tileGIDAt(tmpTileCoord); if (tileGid) { CCDictionary *properties = _tileMap->propertiesForGID(tileGid); if (properties) { // obstacle CCString *collision = new CCString(); // Breakableのみ戻す *collision = *properties->valueForKey("Breakable"); if (collision && (collision->compare("True") == 0)) { CCSprite *sprite = _background->tileAt(tmpTileCoord); // 白で塗る sprite->setColor(ccWHITE); //sprite->setTag(NOT_TAPPABLE); } } } } }