void UIWidget::setColor(const ccColor3B &color) { CCRGBAProtocol* rgbap = DYNAMIC_CAST_CCRGBAPROTOCOL; if (rgbap) { rgbap->setColor(color); } }
void Layout::updateBackGroundImageColor() { CCRGBAProtocol* rgba = dynamic_cast<CCRGBAProtocol*>(_backGroundImage); if (rgba) { rgba->setColor(_backGroundImageColor); } }
void CCTintBy::update(cocos2d::ccTime time) { CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol(); if (pRGBAProtocol) { pRGBAProtocol->setColor(ccc3((GLubyte)(m_fromR + m_deltaR * time), (GLubyte)(m_fromG + m_deltaG * time), (GLubyte)(m_fromB + m_deltaB * time))); } }
void CCTintTo::update(ccTime time) { CCRGBAProtocol *pRGBAProtocol = dynamic_cast<CCRGBAProtocol*>(m_pTarget); if (pRGBAProtocol) { pRGBAProtocol->setColor(ccc3(CCubyte(m_from.r + (m_to.r - m_from.r) * time), (CCbyte)(m_from.g + (m_to.g - m_from.g) * time), (CCbyte)(m_from.b + (m_to.b - m_from.b) * time))); } }
void CCTintBy::update(ccTime time) { CCRGBAProtocol *pRGBAProtocol = dynamic_cast<CCRGBAProtocol*>(m_pTarget); if (pRGBAProtocol) { pRGBAProtocol->setColor(ccc3((CCubyte)(m_fromR + m_deltaR * time), (CCubyte)(m_fromG + m_deltaG * time), (CCubyte)(m_fromB + m_deltaB * time))); } }
void CCTintTo::update(cocos2d::ccTime time) { CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol(); if (pRGBAProtocol) { pRGBAProtocol->setColor(ccc3(GLubyte(m_from.r + (m_to.r - m_from.r) * time), (GLbyte)(m_from.g + (m_to.g - m_from.g) * time), (GLbyte)(m_from.b + (m_to.b - m_from.b) * time))); } }
void GUINodeRGBA::addChild(cocos2d::CCNode *child) { CCNode::addChild(child); CCRGBAProtocol *item = dynamic_cast<CCRGBAProtocol*>(child); if (item) { item->setColor(this->getColor()); item->setOpacity(this->getOpacity()); } }
void UILayout::setColor(const ccColor3B &color) { UIWidget::setColor(color); if (m_pBackGroundImage) { CCRGBAProtocol* rgbap = dynamic_cast<CCRGBAProtocol*>(m_pBackGroundImage); if (rgbap) { rgbap->setColor(color); } } }
void GUINodeRGBA::setColor(const cocos2d::ccColor3B &color3) { CCNodeRGBA::setColor(color3); CCObject* pObj; CCARRAY_FOREACH(m_pChildren, pObj) { CCRGBAProtocol *item = dynamic_cast<CCRGBAProtocol*>(pObj); if (item) { item->setColor(color3); } }
//CRGBA protocol void CCControl::setColor(const ccColor3B& color) { m_tColor=color; CCObject* child; CCArray* children=getChildren(); CCARRAY_FOREACH(children, child) { CCRGBAProtocol* pNode = dynamic_cast<CCRGBAProtocol*>(child); if (pNode) { pNode->setColor(m_tColor); } }
void CCSpecialSprite::setColor(const ccColor3B & color3) { CCSprite::setColor(color3); Vector<CCNode *>::const_iterator beg = _children.begin(); Vector<CCNode *>::const_iterator end = _children.end(); for (; beg != end; ++beg) { CCRGBAProtocol * rgba = dynamic_cast<CCRGBAProtocol *>(*beg); if (rgba != NULL) rgba->setColor(color3); } }
void CCSpecialSprite::addChild(CCNode *pChild, int zOrder, int tag) { CCSprite::addChild(pChild, zOrder, tag); setTexture(((CCSprite*)pChild)->getTexture()); CCRGBAProtocol * rgba = dynamic_cast<CCRGBAProtocol *>(pChild); if (rgba != NULL) { rgba->setColor(this->getColor()); rgba->setOpacity(this->getOpacity()); } }
void CArmySprite::underAttack(int nHurt) { if (m_eCurState >= AS_EXPLODE) { return ; } m_sCurData.mHealthPoint -= nHurt; if (m_bIsNormal) { m_bIsNormal = false; CCRGBAProtocol *pRGBAProtocol = dynamic_cast<CCRGBAProtocol*>(m_pTurretSprite); color = pRGBAProtocol->getColor(); pRGBAProtocol->setColor(ccc3(255,0,0)); } if (m_sCurData.mHealthPoint < 0) { m_sCurData.mHealthPoint = 0; m_eCurState = AS_EXPLODE; m_pTurretSprite->setVisible(false); m_pBaseSprite->setVisible(false); if (m_pCapSprite) { m_pCapSprite->setVisible(false); } m_pWreckSprite->setVisible(true); CGlobalData::getSingleton()->addScore(m_sCurData.mScoreValue); Music::playExplode2Effect(); CGlobalData::getSingleton()->addDesArmyScore(m_sCurLandData.mKind); ASSESS_DATA mData; if (CCRANDOM_0_1() > 0.5f) { mData.mKind = ASK_PERFECT; } else { mData.mKind = ASK_DEFAULT; } mData.mPos = getPosition(); CAssess *pAssess = CAssess::createAssess(mData); getParent()->addChild(pAssess, ASSESS_ZORDER); mData.mKind = ASK_ADD100; mData.mPos = ccpAdd(mData.mPos, ccp(0, getContentSize().height * 0.5f)); pAssess = CAssess::createAssess(mData); getParent()->addChild(pAssess, ASSESS_ZORDER); runEffect(); } }
void CCScale9Sprite::setColor(const ccColor3B& color) { _color = color; CCObject* child; CCArray* children = this->getSubviews(); CCARRAY_FOREACH(children, child) { CCRGBAProtocol* pNode = dynamic_cast<CCRGBAProtocol*>(child); if (pNode) { pNode->setColor(color); } }
void CCMenu::setColor(cocos2d::ccColor3B var) { m_tColor = var; if (m_pChildren && m_pChildren->count() > 0) { NSMutableArray<CCNode*>::NSMutableArrayIterator it; for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it) { if (! *it) { break; } CCRGBAProtocol *pRGBAProtocol = (*it)->convertToRGBAProtocol(); if (pRGBAProtocol) { pRGBAProtocol->setColor(m_tColor); } } } }
void CCControlButton::needsLayout() { if (!m_bParentInited) { return; } // Hide the background and the label if (m_titleLabel != NULL) { m_titleLabel->setIsVisible(false); } if (m_backgroundSprite) { m_backgroundSprite->setIsVisible(false); } // Update anchor of all labels this->setLabelAnchorPoint(this->m_labelAnchorPoint); // Update the label to match with the current state CC_SAFE_RELEASE(m_currentTitle); m_currentTitle = getTitleForState(m_eState); CC_SAFE_RETAIN(m_currentTitle); m_currentTitleColor=getTitleColorForState(m_eState); this->setTitleLabel(getTitleLabelForState(m_eState)); CCLabelProtocol* label = dynamic_cast<CCLabelProtocol*>(m_titleLabel); if (label && m_currentTitle) { label->setString(m_currentTitle->toStdString().c_str()); } CCRGBAProtocol* rgbaLabel = dynamic_cast<CCRGBAProtocol*>(m_titleLabel); if (rgbaLabel) { rgbaLabel->setColor(m_currentTitleColor); } if (m_titleLabel != NULL) { m_titleLabel->setPosition(ccp (getContentSize().width / 2, getContentSize().height / 2)); } // Update the background sprite this->setBackgroundSprite(this->getBackgroundSpriteForState(m_eState)); if (m_backgroundSprite != NULL) { m_backgroundSprite->setPosition(ccp (getContentSize().width / 2, getContentSize().height / 2)); } // Get the title label size CCSize titleLabelSize; if (m_titleLabel != NULL) { titleLabelSize = m_titleLabel->boundingBox().size; } // Adjust the background image if necessary if (m_doesAdjustBackgroundImage) { // Add the margins if (m_backgroundSprite != NULL) { m_backgroundSprite->setContentSize(CCSizeMake(titleLabelSize.width + m_marginH * 2, titleLabelSize.height + m_marginV * 2)); } } else { //TODO: should this also have margins if one of the preferred sizes is relaxed? if (m_backgroundSprite != NULL) { CCSize preferredSize = m_backgroundSprite->getPreferredSize(); if (preferredSize.width <= 0) { preferredSize.width = titleLabelSize.width; } if (preferredSize.height <= 0) { preferredSize.height = titleLabelSize.height; } m_backgroundSprite->setContentSize(preferredSize); } } // Set the content size CCRect rectTitle; if (m_titleLabel != NULL) { rectTitle = m_titleLabel->boundingBox(); } CCRect rectBackground; if (m_backgroundSprite != NULL) { rectBackground = m_backgroundSprite->boundingBox(); } CCRect maxRect = CCControlUtils::CCRectUnion(rectTitle, rectBackground); setContentSize(CCSizeMake(maxRect.size.width, maxRect.size.height)); if (m_titleLabel != NULL) { m_titleLabel->setPosition(ccp(getContentSize().width/2, getContentSize().height/2)); // Make visible the background and the label m_titleLabel->setIsVisible(true); } if (m_backgroundSprite != NULL) { m_backgroundSprite->setPosition(ccp(getContentSize().width/2, getContentSize().height/2)); m_backgroundSprite->setIsVisible(true); } }
void RichText::formatText() { if (_formatTextDirty) { _elementRenderersContainer->removeAllChildren(); _elementRenders.clear(); if (_ignoreSize) { addNewLine(); for (unsigned int i=0; i<_richElements->count(); i++) { RichElement* element = static_cast<RichElement*>(_richElements->objectAtIndex(i)); CCNode* elementRenderer = NULL; switch (element->_type) { case RICH_TEXT: { RichElementText* elmtText = static_cast<RichElementText*>(element); elementRenderer = CCLabelTTF::create(elmtText->_text.c_str(), elmtText->_fontName.c_str(), elmtText->_fontSize); break; } case RICH_IMAGE: { RichElementImage* elmtImage = static_cast<RichElementImage*>(element); elementRenderer = CCSprite::create(elmtImage->_filePath.c_str()); break; } case RICH_CUSTOM: { RichElementCustomNode* elmtCustom = static_cast<RichElementCustomNode*>(element); elementRenderer = elmtCustom->_customNode; break; } default: break; } CCRGBAProtocol* colorRenderer = dynamic_cast<CCRGBAProtocol*>(elementRenderer); colorRenderer->setColor(element->_color); colorRenderer->setOpacity(element->_opacity); pushToContainer(elementRenderer); } } else { addNewLine(); for (unsigned int i=0; i<_richElements->count(); i++) { RichElement* element = static_cast<RichElement*>(_richElements->objectAtIndex(i)); switch (element->_type) { case RICH_TEXT: { RichElementText* elmtText = static_cast<RichElementText*>(element); handleTextRenderer(elmtText->_text.c_str(), elmtText->_fontName.c_str(), elmtText->_fontSize, elmtText->_color, elmtText->_opacity); break; } case RICH_IMAGE: { RichElementImage* elmtImage = static_cast<RichElementImage*>(element); handleImageRenderer(elmtImage->_filePath.c_str(), elmtImage->_color, elmtImage->_opacity); break; } case RICH_CUSTOM: { RichElementCustomNode* elmtCustom = static_cast<RichElementCustomNode*>(element); handleCustomRenderer(elmtCustom->_customNode); break; } default: break; } } } formarRenderers(); _formatTextDirty = false; } }
void CArmySprite::enemyUpdate(float fEscapeTime) { switch(m_eCurState) { case AS_DEFAULT: break; case AS_MOVE: //if (getPosition().y < -getContentSize().height || getPosition().y > mScreenSize.height - BANNER_HEIGHT + getContentSize().height) //{ // m_eCurState = BS_HIDE; //} m_fFireCoolTime += fEscapeTime; if (m_fFireCoolTime > 2.0f) { fireBullet(fEscapeTime); } break; case AS_EXPLODE: break; case AS_HIDE: if(getPosition().y < -getContentSize().height * 0.5f) { getParent()->removeChild(this, true); } break; } if (m_eCurState < AS_EXPLODE && m_sCurData.mKind < AK_BUNKER01) { CCNode *m_pTarget = (CCNode*)(getParent()->getChildByTag(PALYER_TYPE)); float o = m_pTarget->getPosition().x - getPosition().x; float a = m_pTarget->getPosition().y - getPosition().y; float at = (float) CC_RADIANS_TO_DEGREES( atanf( o/a) ); if( a < 0 ) { if( o < 0 ) at = 180 + fabs(at); else at = 180 - fabs(at); } m_pTurretSprite->setRotation(180 + at); } if (getPosition().y > -getContentSize().height * 0.5f) { setPosition(ccpAdd(getPosition(),ccpMult(ccp(0.0f, -1.0f), m_sCurData.mMoveSpeed * fEscapeTime))); } else { m_eCurState = AS_HIDE; } if (!m_bIsNormal) { m_fFlashTime += fEscapeTime; if (m_fFlashTime > 0.1f) { m_fFlashTime = 0.0f; CCRGBAProtocol *pRGBAProtocol = dynamic_cast<CCRGBAProtocol*>(m_pTurretSprite); pRGBAProtocol->setColor(color); m_bIsNormal = true; } } }
void NodeReader::initNode(cocos2d::CCNode* node, const rapidjson::Value& json) { float x = DICTOOL->getFloatValue_json(json, X); float y = DICTOOL->getFloatValue_json(json, Y); float scalex = DICTOOL->getFloatValue_json(json, SCALE_X, 1); float scaley = DICTOOL->getFloatValue_json(json, SCALE_Y, 1); float rotation = DICTOOL->getFloatValue_json(json, ROTATION); float rotationSkewX = DICTOOL->getFloatValue_json(json, ROTATION_SKEW_X); float rotationSkewY = DICTOOL->getFloatValue_json(json, ROTATION_SKEW_X); float skewx = DICTOOL->getFloatValue_json(json, SKEW_X); float skewy = DICTOOL->getFloatValue_json(json, SKEW_Y); float anchorx = DICTOOL->getFloatValue_json(json, ANCHOR_X, 0.5f); float anchory = DICTOOL->getFloatValue_json(json, ANCHOR_Y, 0.5f); GLubyte alpha = (GLubyte)DICTOOL->getIntValue_json(json, ALPHA, 255); GLubyte red = (GLubyte)DICTOOL->getIntValue_json(json, RED, 255); GLubyte green = (GLubyte)DICTOOL->getIntValue_json(json, GREEN, 255); GLubyte blue = (GLubyte)DICTOOL->getIntValue_json(json, BLUE, 255); int zorder = DICTOOL->getIntValue_json(json, ZORDER); int tag = DICTOOL->getIntValue_json(json, TAG); int actionTag = DICTOOL->getIntValue_json(json, ACTION_TAG); bool visible = DICTOOL->getBooleanValue_json(json, VISIBLE); if(x != 0 || y != 0) node->setPosition(CCPoint(x, y)); if(scalex != 1) node->setScaleX(scalex); if(scaley != 1) node->setScaleY(scaley); if (rotation != 0) node->setRotation(rotation); if(rotationSkewX != 0) node->setRotationX(rotationSkewX); if(rotationSkewY != 0) node->setRotationY(rotationSkewY); if(skewx != 0) node->setSkewX(skewx); if(skewy != 0) node->setSkewY(skewy); if(anchorx != 0.5f || anchory != 0.5f) node->setAnchorPoint(CCPoint(anchorx, anchory)); if(zorder != 0) node->setZOrder(zorder); if(visible != true) node->setVisible(visible); CCRGBAProtocol *rgbaProtocaol = dynamic_cast<CCRGBAProtocol *>(node); if(rgbaProtocaol) { if(alpha != 255) { rgbaProtocaol->setOpacity(alpha); } if(red != 255 || green != 255 || blue != 255) { rgbaProtocaol->setColor(ccc3(red, green, blue)); } } node->setTag(tag); node->setUserObject(TimelineActionData::create(actionTag)); }