CCNode* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner, const CCSize &parentSize) { if (NULL == pCCBFileName || strlen(pCCBFileName) == 0) { return NULL; } std::string strCCBFileName(pCCBFileName); std::string strSuffix(".ccbi"); // Add ccbi suffix if (!CCBReader::endsWith(strCCBFileName.c_str(), strSuffix.c_str())) { strCCBFileName += strSuffix; } std::string strPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(strCCBFileName.c_str()); unsigned long size = 0; unsigned char * pBytes = CCFileUtils::sharedFileUtils()->getFileData(strPath.c_str(), "rb", &size); CCData *data = new CCData(pBytes, size); CC_SAFE_DELETE_ARRAY(pBytes); CCNode *ret = this->readNodeGraphFromData(data, pOwner, parentSize); data->release(); // (jason_shi): 将未命名的JSController命名为路径名 CCBAnimationManager* animMgr = (CCBAnimationManager*)ret->getUserObject(); std::string controllerName = animMgr->getDocumentControllerName(); if (controllerName.compare("") == 0) { animMgr->setDocumentControllerName(pCCBFileName); } return ret; }
void CCINode::applyColorTransform(cocos2d::CCNode *node, ccColor4B colorTransform){ CCArray * children = node->getChildren(); for (int i=0; i<node->getChildrenCount(); i++) { CCNode * childNode = (CCNode *)children->objectAtIndex(i); CCInteger * type = (CCInteger *)childNode->getUserObject(); if (type->getValue()==NodeTypeSprite) { CCSprite * sprite = (CCSprite *)childNode; sprite->setColor(ccc3(colorTransform.r, colorTransform.g, colorTransform.b)); sprite->setOpacity(colorTransform.a); }else{ this->applyColorTransform(childNode, colorTransform); } } }
bool FMMapAvatarNode::addAvatarNode(CCDictionary * dic) { if (m_avatarList->count() >= 4) { return false; } FMDataManager * manager = FMDataManager::sharedManager(); FMMainScene * mainScene = (FMMainScene *)FMDataManager::sharedManager()->getUI(kUI_MainScene); FMWorldMapNode* wd = (FMWorldMapNode*)mainScene->getNode(kWorldMapNode); CCNode * n = manager->createNode("UI/FMUIAvatar.ccbi", wd); addChild(n,10-m_avatarList->count(),m_avatarList->count()); m_avatarList->addObject(n); CCString * uid = (CCString *)dic->objectForKey("uid"); const char * iconpath = SNSFunction_getFacebookIcon(uid->getCString()); CCSprite * icon = (CCSprite*)n->getChildByTag(1); if (iconpath && manager->isFileExist(iconpath)) { CCSprite * spr = CCSprite::create(iconpath); float size = 26.f; spr->setScale(size / MAX(spr->getContentSize().width, size)); icon->addChild(spr); spr->setPosition(ccp(icon->getContentSize().width/2, icon->getContentSize().height/2)); } int cnt = m_avatarList->count()-1; if (m_includeSelf) { cnt++; } n->setPosition(ccp(cnt * avatarDiffx, cnt * avatarDiffy)); CCBAnimationManager * anim = (CCBAnimationManager *)n->getUserObject(); anim->runAnimationsForSequenceNamed("2"); m_dicList->addObject(dic); return true; }
void CCINode::showFrame(){ //std::vector<CCIMovieTag *> tags = this->swfMovie->getTags(); while (true) { CCIMovieTag * tag = NULL; if (currentTag<tags.size()) { tag = tags[currentTag++]; }else{ this->removeAllChildrenWithCleanup(true); //this->stop(); currentTag = 0; currentFrame = 0; break; } if(tag->getTagType()==TagTypePlaceObject||tag->getTagType()==TagTypePlaceObject2||tag->getTagType()==TagTypePlaceObject3){ CCIPlaceObject * placeTag = (CCIPlaceObject *)tag; int charactorId = placeTag->getCharacterId(); int depth = placeTag->getDepth(); CCIPlaceObject2 * placeTag2 = NULL; if (tag->getTagType()==TagTypePlaceObject2||tag->getTagType()==TagTypePlaceObject3) { placeTag2 = (CCIPlaceObject2 *)tag; } CCNode * node; if (!placeTag2||placeTag2->placeType==PlaceObjectTypeNew) { //place1 or placetag2 new node = (CCNode *)this->nodes->objectForKey(charactorId); if (node&&node->getParent()==NULL) { this->addChild(node, depth, depth); CCInteger * nodeType = (CCInteger *)node->getUserObject(); if (nodeType->getValue()==NodeTypeCCINode) { CCINode * ccinode = (CCINode *)node; ccinode->play(); } } }else if(placeTag2&&placeTag2->placeType==PlaceObjectTypeModify){ node = (CCNode *)this->getChildByTag(depth); }else if(placeTag2&&placeTag2->placeType==PlaceObjectTypeReplace){ CCNode * newNode = (CCNode *)this->nodes->objectForKey(charactorId); node = (CCNode *)this->getChildByTag(depth); if (node) { if (newNode) { //get last transform matrix newNode->setPosition(node->getPosition()); newNode->setScaleX(node->getScaleX()); newNode->setScaleY(node->getScaleY()); newNode->setSkewX(node->getSkewX()); newNode->setSkewY(node->getSkewY()); } CCInteger * nodeType = (CCInteger *)node->getUserObject(); if (nodeType->getValue()==NodeTypeCCINode) { CCINode * ccinode = (CCINode *)node; ccinode->stop(); } node->removeFromParentAndCleanup(true); } node = newNode; if (node&&node->getParent()==NULL) { this->addChild(node, depth, depth); CCInteger * nodeType = (CCInteger *)node->getUserObject(); if (nodeType->getValue()==NodeTypeCCINode) { CCINode * ccinode = (CCINode *)node; ccinode->play(); } } } if (node) { CCIMatrix * matrix = placeTag->getMatrix(); if (matrix) { int x = matrix->getTranslateX(); int y = matrix->getTranslateY(); node->setPosition(this->swfMovie->getHeader()->getBounds()->convertToCCSpace(x, y)); //restore float scaleX = 1.0; float scaleY = 1.0; node->setScaleX(1); node->setScaleY(1); node->setSkewX(0); node->setSkewY(0); if (matrix->HasScale) { scaleX = matrix->getScaleX(); scaleY = matrix->getScaleY(); node->setScaleX(scaleX); node->setScaleY(scaleY); } if (matrix->HasRotate) { float skewX = matrix->getSkewX(); float skewY = matrix->getSkewY(); this->applySkew(node, skewX, skewY,false); } } CCICxform * colorTransform = placeTag->getColorTransform(); int red = 255; int green = 255; int blue = 255; int alpha = 255; if (colorTransform) { if (colorTransform->HasMultTerms) { red = colorTransform->RedMultTerm-1; green = colorTransform->GreenMultTerm-1; blue = colorTransform->BlueMultTerm-1; if (colorTransform->hasAlpha()) { CCICxformWithAlpha * cxformAlpha = (CCICxformWithAlpha *)colorTransform; alpha = cxformAlpha->AlphaMultTerm-1; } } if (colorTransform->HasAddTerms) { //TODO no add term } if (red==-1) { red = 0; } if (green ==-1) { green = 0; } if (blue == -1) { blue = 0; } if (alpha ==-1) { alpha = 0; } } this->applyColorTransform(node, ccc4(red, green, blue, alpha)); if (tag->getTagType()==TagTypePlaceObject3) { //check filters CCIPlaceObject3 * placeTag3 = (CCIPlaceObject3 *)tag; CCIFilterList * filterList = placeTag3->getFilterList(); if (filterList) { //apply filter list for (int i=0; i<filterList->NumberOfFilters; i++) { //CCIFilter * filter = filterList->Filter[i]; } } } } }else if (tag->getTagType()==TagTypeRemoveObject||tag->getTagType()==TagTypeRemoveObject2){ CCIRemoveObject * removeTag = (CCIRemoveObject *)tag; int depth = removeTag->getDepth(); CCNode * node = this->getChildByTag(depth); if (node) { CCInteger * nodeType = (CCInteger *)node->getUserObject(); if (nodeType->getValue()==NodeTypeCCINode) { CCINode * ccinode = (CCINode *)node; ccinode->stop(); } node->removeFromParentAndCleanup(true); } }else if(tag->getTagType()==TagTypeFrameLabel){ if (isPlayingFrameLabel&¤tTag!=frameLabelIndex) { currentTag = frameLabelIndex; currentFrame = 0; //this->removeAllChildrenWithCleanup(true); break; } }else if(tag->getTagType()==TagTypeShowFrame){ if (this->delegate) { this->delegate->didEnterFrame(currentFrame, this->frameLabel); } currentFrame++; break; } } }