CCNode * CCNodeLoader::parsePropTypeCCBFile(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) { CCString * ccbFileName = pCCBReader->readCachedString(); /* Change path extension to .ccbi. */ CCString * ccbFileWithoutPathExtension = CCBReader::deletePathExtension(ccbFileName); ccbFileName = CCBReader::concat(ccbFileWithoutPathExtension, CCString::create(".ccbi")); // Load sub file const char *path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(ccbFileName->getCString()); CCBReader * ccbReader = new CCBReader(pCCBReader); ccbReader->autorelease(); unsigned long size; unsigned char * pBytes = CCFileUtils::sharedFileUtils()->getFileData(path, "rb", &size); CCData *data = new CCData(pBytes, size); ccbReader->initWithData(data, pCCBReader->getOwner()); data->release(); ccbReader->getAnimationManager()->setRootContainerSize(pParent->getContentSize()); CCNode * ccbFileNode = ccbReader->readFileWithCleanUp(false); if (ccbFileNode && ccbReader->getAnimationManager()->getAutoPlaySequenceId() != -1) { // Auto play animations ccbReader->getAnimationManager()->runAnimations(ccbReader->getAnimationManager()->getAutoPlaySequenceId(), 0); } return ccbFileNode; }
bool Background::Init() { do { CCNodeLoaderLibrary * ccNodeLoaderLibraryLeft = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary(); CCBReader * ccbReaderLeft = new CCBReader(ccNodeLoaderLibraryLeft); CCNode * bgLeft = ccbReaderLeft->readNodeGraphFromFile("ccb/background.ccbi", this); CCBAnimationManager* animationManagerLeft = ccbReaderLeft->getAnimationManager(); animationManagerLeft->runAnimationsForSequenceNamed("left"); ccbReaderLeft->release(); CCNodeLoaderLibrary * ccNodeLoaderLibraryRight = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary(); CCBReader * ccbReaderRight = new CCBReader(ccNodeLoaderLibraryRight); CCNode * bgRight = ccbReaderRight->readNodeGraphFromFile("ccb/background.ccbi", this); CCBAnimationManager* animationManagerRight = ccbReaderRight->getAnimationManager(); animationManagerRight->runAnimationsForSequenceNamed("right"); ccbReaderRight->release(); CCClippingNode * clippingNodeLeft = CCClippingNode::create(); addChild(clippingNodeLeft); clippingNodeLeft->addChild(bgLeft,enZOrderBack,enTagBgLeft); CCDrawNode *shapeLeft = CCDrawNode::create(); static CCPoint triangleLeft[3]; triangleLeft[0] = ccp(0, 0); triangleLeft[1] = ccp(SCREEN_WIDTH,0); triangleLeft[2] = ccp(0,SCREEN_HEIGHT); static ccColor4F green = {0, 1, 0, 1}; shapeLeft->drawPolygon(triangleLeft, 3, green, 0, green); clippingNodeLeft->setStencil(shapeLeft); clippingNodeLeft->setInverted(false); CCClippingNode * clippingNodeRight = CCClippingNode::create(); addChild(clippingNodeRight); clippingNodeRight->addChild(bgRight,enZOrderBack,enTagBgRight); CCDrawNode *shapeRight = CCDrawNode::create(); static CCPoint triangleRight[3]; triangleRight[0] = ccp(SCREEN_WIDTH, SCREEN_HEIGHT); triangleRight[1] = ccp(SCREEN_WIDTH,0); triangleRight[2] = ccp(0,SCREEN_HEIGHT); // static ccColor4F green = {0, 1, 0, 1}; shapeRight->drawPolygon(triangleRight, 3, green, 0, green); clippingNodeRight->setStencil(shapeRight); clippingNodeRight->setInverted(false); m_CraterArrayLeft = CCArray::create(); m_CraterArrayLeft->retain(); m_CraterArrayRight = CCArray::create(); m_CraterArrayRight->retain(); m_CraterArrayLeftDeleted = CCArray::create(); m_CraterArrayLeftDeleted->retain(); m_CraterArrayRightDeleted = CCArray::create(); m_CraterArrayRightDeleted->retain(); return true; } while (false); CCLog("Function Background::Init Error!"); return false; }
void Background::OnDead(enUnitIndex target, CCPoint targetPos) { enUnitType eType = GlobalData::sharedDirector()->getUnitTypeByIndex(target); unitDataMap unitData = GlobalData::sharedDirector()->getUnitDefaultData(); // unitPosMap unitsPos = GlobalData::sharedDirector()->getUnitPos(); if(eType==enUnitTypeTroopMine || eType==enUnitTypeTroopEnemy) { CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary(); CCBReader * ccbReader = new CCBReader(ccNodeLoaderLibrary); CCNode * ccbNode = ccbReader->readNodeGraphFromFile(unitData[eType].strCCBI.c_str(), this); CCBAnimationManager* animationManager = ccbReader->getAnimationManager(); animationManager->runAnimationsForSequenceNamed("dead"); ccbReader->release(); ccbNode->setScaleX(0.5);//the bg sprite in ccb is scale. if(target<enUnitIndexEnemy1) { m_backgroundLeft->addChild(ccbNode); ccbNode->setPosition(m_backgroundLeft->convertToNodeSpace(targetPos)); m_CraterArrayLeft->addObject(ccbNode); } else { m_backgroundRight->addChild(ccbNode); ccbNode->setPosition(m_backgroundRight->convertToNodeSpace(targetPos)); m_CraterArrayRight->addObject(ccbNode); } } else if(eType==enUnitTypeCarMine || eType==enUnitTypeCarEnemy) { CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary(); CCBReader * ccbReader = new CCBReader(ccNodeLoaderLibrary); CCNode * ccbNode = ccbReader->readNodeGraphFromFile("ccb/boom.ccbi", this); CCBAnimationManager* animationManager = ccbReader->getAnimationManager(); animationManager->runAnimationsForSequenceNamed("boom"); ccbReader->release(); ccbNode->setScaleX(0.5);//the bg sprite in ccb is scale. if(target<enUnitIndexEnemy1) { m_backgroundLeft->addChild(ccbNode); ccbNode->setPosition(m_backgroundLeft->convertToNodeSpace(targetPos)); m_CraterArrayLeft->addObject(ccbNode); } else { m_backgroundRight->addChild(ccbNode); ccbNode->setPosition(m_backgroundRight->convertToNodeSpace(targetPos)); m_CraterArrayRight->addObject(ccbNode); } } }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); auto eglView = EGLView::getInstance(); director->setOpenGLView(eglView); // turn on display FPS director->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object auto scene = Scene::create(); #if 0 NodeLoaderLibrary *pLoaderLibrary = NodeLoaderLibrary::newDefaultNodeLoaderLibrary(); CCBReader *ccbReader = new CCBReader(pLoaderLibrary); pLoaderLibrary->registerNodeLoader("plane_figtht_main", XCMainMenuLoader::loader()); Node *pMainMenu = ccbReader->readNodeGraphFromFile("ccb/ccbi/plane_fight_main.ccbi"); dynamic_cast<XCMainMenu*>(pMainMenu)->setAnimationManager(ccbReader->getAnimationManager()); dynamic_cast<XCMainMenu*>(pMainMenu)->initPlaneMain(); ccbReader->release(); scene->addChild(pMainMenu); #else #endif // run director->runWithScene(scene); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director CCDirector* pDirector = CCDirector::sharedDirector(); CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); pDirector->setOpenGLView(pEGLView); // デザインサイズの設定 pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder); CCSize frameSize = pEGLView->getFrameSize(); std::vector<std::string> searchPath; if (frameSize.height > largeResource.size.height) { // iPad Retina用リソースを使用 searchPath.push_back(xlargeResource.directory); pDirector->setContentScaleFactor(MIN(xlargeResource.size.height / designResolutionSize.height, xlargeResource.size.width / designResolutionSize.width)); } else if (frameSize.height > smallResource.size.height) { // iPad用リソースを使用 searchPath.push_back(largeResource.directory); pDirector->setContentScaleFactor(MIN(largeResource.size.height / designResolutionSize.height, largeResource.size.width / designResolutionSize.width)); } else { // iPhone用リソースを使用 searchPath.push_back(smallResource.directory); pDirector->setContentScaleFactor(MIN(smallResource.size.height / designResolutionSize.height, smallResource.size.width / designResolutionSize.width)); } // リソースディレクトリを指定 CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath); // turn on display FPS pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); // CocosBuilderのファイルを読み込みゲーム画面を生成する CCNodeLoaderLibrary* ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary(); ccNodeLoaderLibrary->registerCCNodeLoader("GameLayer", GameLayerLoader::loader()); CCBReader* ccbReader = new CCBReader(ccNodeLoaderLibrary); CCNode* node = ccbReader->readNodeGraphFromFile("GameLayer.ccbi"); ((GameLayer*)node)->setAnimationManager(ccbReader->getAnimationManager()); // シーンを用意し、ゲーム画面を設置する CCScene* pScene = CCScene::create(); if (node != NULL) pScene->addChild(node); ccbReader->release(); // run pDirector->runWithScene(pScene); return true; }
bool Unit::Init(enUnitType eType, enUnitIndex eIndex) { do { unitDataMap unitData = GlobalData::sharedDirector()->getUnitDefaultData(); m_unitData = unitData[eType]; m_nFireCd = m_unitData.nFireCD; m_eUnitType = m_unitData.eType; m_eUnitStatus = enUnitStatusPre; m_nHp = m_unitData.nHp; m_eUnitIndex = eIndex; CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary(); CCBReader * ccbReader = new CCBReader(ccNodeLoaderLibrary); CCNode * ccbNode = ccbReader->readNodeGraphFromFile(m_unitData.strCCBI.c_str(), this); m_animationManager = ccbReader->getAnimationManager(); m_animationManager->runAnimationsForSequenceNamed("run"); m_animationManager->setAnimationCompletedCallback(this, callfunc_selector(Unit::AnimationCallBack)); ccbReader->release(); addChild(ccbNode); return true; } while (false); CCLog("Function Unit::Init Error!"); return false; }
// Constructor for the enemy. The layer is initialized in Model's constructor. Enemy::Enemy(int x, int y) : Model(x,y) { // Create a default NodeLoaderLibrary. NodeLoaderLibrary* nodeLoaderLibrary; nodeLoaderLibrary = NodeLoaderLibrary::newDefaultNodeLoaderLibrary(); // Create a new CCBReader with a default NodeLoaderLibrary // This can take a lot of parameters to use code connections and more CCBReader* ccbReader = new CCBReader(nodeLoaderLibrary); // Load the main node from the CocosBuilder file modelNodes = ccbReader->readNodeGraphFromFile("Orc.ccbi"); // Get the animationmanager so we can animate the thing afterwards animationManager = ccbReader->getAnimationManager(); modelNodes->setPosition( Point(x, y)); //modelNodes->setScale(0.5f); Node* rShoulder = modelNodes->getChildByTag(1)->getChildByTag(4)->getChildByTag(1); rShoulder->setZOrder(0); Node* lHip = modelNodes->getChildByTag(1)->getChildByTag(1); lHip->setZOrder(0); Node* rHip = modelNodes->getChildByTag(1)->getChildByTag(2); rHip->setZOrder(0); Node* rUpperArm = rShoulder->getChildByTag(2); rUpperArm->setZOrder(-1); Node* chest = modelNodes->getChildByTag(1)->getChildByTag(4)->getChildByTag(2); chest->setZOrder(0); Node* hips = modelNodes->getChildByTag(1)->getChildByTag(3); hips->setZOrder(0); modelNodes->getChildByTag(1)->getChildByTag(4)->setZOrder(0); Node* lShoulder = modelNodes->getChildByTag(1)->getChildByTag(4)->getChildByTag(4); lShoulder->setZOrder(3); Node* rElbow = rShoulder->getChildByTag(1); rElbow->setZOrder(1); Node* rLowerArm = rShoulder->getChildByTag(1)->getChildByTag(1); rLowerArm->setZOrder(2); Node* rHand = rShoulder->getChildByTag(1)->getChildByTag(2); rHand->getChildByTag(1)->setVisible(true); rHand->setZOrder(2); Node* neck = modelNodes->getChildByTag(1)->getChildByTag(4)->getChildByTag(3); neck->setZOrder(2); this->addChild(modelNodes); // Add the loaded node to the scene (this) healthStatus->setPosition(Point(x-500, y+100)); this->addChild(healthStatus); initAttacks(); // As nobody called ccbReader->autoRelease(), returning now would cause // a memory leak. We can call autoRelease or delete it ourselves. delete ccbReader; }
Bomb* Bomb::bomb() { CCNodeLoaderLibrary *nodeLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary(); nodeLibrary->registerCCNodeLoader("Bomb", BombLoader::loader()); CCBReader *ccbReader = new CCBReader(nodeLibrary); Bomb *node = (Bomb *)ccbReader->readNodeGraphFromFile("ccb/bomb"); ccbReader->getAnimationManager()->setAnimationCompletedCallback(node, callfunc_selector(Bomb::test)); ccbReader->release(); // CCBAnimationManager * ccbManager = (CCBAnimationManager *)node->getUserObject(); // ccbManager->setAnimationCompletedCallback(node, callfunc_selector(Bomb::test)); return node; }
void CSpriteObject::clearThis() { CCBReader* pCCBReader = getCCBReader(); if (pCCBReader) { pCCBReader->getAnimationManager()->setDelegate(NULL); } setCCBReader(NULL); setActionDelegate(NULL); if (pSprite_ != NULL) { pSprite_->removeFromParentAndCleanup(true); setInnerSprite(NULL); } }
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 ; }
void NBGCCBReader::readCCB(const char * ccbiName) { releaseMembers(); /* Create an autorelease NodeLoaderLibrary. */ NodeLoaderLibrary* ccNodeLoaderLibrary = NodeLoaderLibrary::newDefaultNodeLoaderLibrary(); /* Create an autorelease CCBReader. */ CCBReader* ccbReader = new CCBReader(ccNodeLoaderLibrary); ccbReader->setCCBRootPath(CCBRESOURCES_BASE_PATH); ccbReader->autorelease(); /* Read a ccbi file. */ m_pCCBNode = ccbReader->readNodeGraphFromFile(ccbiName, this); if (m_pCCBNode != nullptr) { m_pAnimationManager = ccbReader->getAnimationManager(); m_pAnimationManager->setDelegate(this); } CC_SAFE_RETAIN(m_pCCBNode); CC_SAFE_RETAIN(m_pAnimationManager); }
bool CSpriteObject::setSpriteFromCcbi(const char* name) { // Create auto-release node loader CCNodeLoaderLibrary* ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary(); // Create a CCBReader, auto release. CCBReader * ccbReader = new CCBReader(ccNodeLoaderLibrary); ccbReader->autorelease(); // Read a ccbi file, return a CCNode instance. setInnerSprite(dynamic_cast<CCSprite*>(ccbReader->readNodeGraphFromFile(name, this))); if (NULL == getInnerSprite()) { return false; } ccbReader->getAnimationManager()->setDelegate(this); setCCBReader(ccbReader); return true; }
Panel* loadCCBFromFileToFenneX(const char* file, const char* inPanel, int zIndex) { if(inPanel == NULL) { animManagers.clear(); } NodeLoaderLibrary * nodeLoaderLibrary = NodeLoaderLibrary::newDefaultNodeLoaderLibrary(); nodeLoaderLibrary->registerNodeLoader("CustomSprite", CustomSpriteLoader::loader()); nodeLoaderLibrary->registerNodeLoader("CustomScaleSprite", CustomScaleSpriteLoader::loader()); nodeLoaderLibrary->registerNodeLoader("CustomNode", CustomNodeLoader::loader()); nodeLoaderLibrary->registerNodeLoader("CustomInput", CustomInputLoader::loader()); nodeLoaderLibrary->registerNodeLoader("CustomLabel", CustomLabelLoader::loader()); nodeLoaderLibrary->registerNodeLoader("CustomDropDownList", CustomDropDownListLoader::loader()); CCBReader *ccbReader = new CCBReader(nodeLoaderLibrary); //IF this one fail, it needs to be silent bool shouldNotify = FileUtils::getInstance()->isPopupNotify(); FileUtils::getInstance()->setPopupNotify(false); #if VERBOSE_PERFORMANCE_TIME timeval startTime; gettimeofday(&startTime, NULL); #endif std::string filePath = ScreateF("%s%s.ccbi", file, isPhone ? "-phone" : "")->getCString(); CCLOG("Filepath : %s", filePath.c_str()); FileUtils::getInstance()->setPopupNotify(shouldNotify); Node* myNode = NULL; if(FileUtils::getInstance()->isFileExist(filePath)) { CCLOG("File exist"); myNode = ccbReader->readNodeGraphFromFile(filePath.c_str()); } else if(isPhone) { myNode = ccbReader->readNodeGraphFromFile(ScreateF("%s.ccbi", file)->getCString()); } #if VERBOSE_PERFORMANCE_TIME timeval middleTime; gettimeofday(&middleTime, NULL); CCLOG("CCBReader loaded file %s in %f ms", file, getTimeDifferenceMS(startTime, middleTime)); #endif //Despite cocosbuilder saying so, Label and Node (for Panel) aren't resized properly, so there it is /*Size frameSize = Director::getInstance()->getWinSize(); float scaleX = (float)frameSize.width / designResolutionSize.width; float scaleY = (float)frameSize.height / designResolutionSize.height; float scale = MAX(scaleX, scaleY); float minScale = MIN(scaleX, scaleY); CCLOG("min : %f, max : %f, loading : %f", minScale, scale, _loadingScale);*/ float usedScale = _loadingScale; //this code is dubious at best .... refactor it later #if VERBOSE_LOAD_CCB CCLOG("ccb file %s loaded, doing rescaling ...", file); #endif for(auto node : myNode->getChildren()) { //Note : Panels are never tested against isKindOfClass because : //against Node, all nodes return true //against CustomNode, a tagging is required on cocosBuilder //Depth 0 of nesting if(isKindOfClass(node, Label)) { Label* label = (Label*)node; #if VERBOSE_LOAD_CCB CCLOG("label font : %s", label->getSystemFontName().c_str()); #endif label->setSystemFontSize(label->getSystemFontSize() * usedScale); /*TTFConfig newConfig = label->getTTFConfig(); newConfig.fontSize *= usedScale; label->setTTFConfig(newConfig);*/ } else if(isKindOfClass(node, CustomInput)) { } else if(isKindOfClass(node, Sprite) || isKindOfClass(node, ui::Scale9Sprite)) { } else if(!node->getChildren().empty())//Panel { node->setScaleX(node->getScaleX()*usedScale); node->setScaleY(node->getScaleY()*usedScale); Node* parentNode = node; for(auto nodeChild : node->getChildren()) { //Depth 1 is a special case too, because nodes don't have to be moved and the scale is not calculated the same way if(isKindOfClass(nodeChild, Label)) { Label* label = (Label*)nodeChild; label->setScale(label->getScale() / parentNode->getScale()); label->setSystemFontSize(label->getSystemFontSize() * parentNode->getScale()); /*TTFConfig newConfig = label->getTTFConfig(); newConfig.fontSize *= parentNode->getScale(); label->setTTFConfig(newConfig);*/ #if VERBOSE_LOAD_CCB CCLOG("label font : %s, size : %f, scale : %f, parent node scale : %f, dimensions : %f, %f, depth 1", label->getSystemFontName().c_str(), label->getSystemFontSize(), label->getScale(), parentNode->getScale(), label->getDimensions().width, label->getDimensions().height); #endif } else if(isKindOfClass(nodeChild, CustomInput)) { //input->setFontSize((float)input->getFontSize() / usedScale); //input->setPreferredSize(Size(input->getPreferredSize().width / usedScale, input->getPreferredSize().height / usedScale)); //input->setFontSize((float)input->getFontSize() * parentNode->getScale()); #if VERBOSE_LOAD_CCB CustomInput* input = (CustomInput*)nodeChild; CCLOG("input font size : %d, parent node scale : %f, dimensions : %f, %f, depth 1", input->getFontSize() , parentNode->getScale(), input->getPreferredSize().width, input->getPreferredSize().height); #endif } else if(isKindOfClass(nodeChild, Sprite)) { nodeChild->setScaleX(nodeChild->getScaleX() / usedScale); nodeChild->setScaleY(nodeChild->getScaleY() / usedScale); } else if(isKindOfClass(nodeChild, ui::Scale9Sprite)) { nodeChild->setScaleX(nodeChild->getScaleX() / usedScale); nodeChild->setScaleY(nodeChild->getScaleY() / usedScale); nodeChild->setContentSize(SizeMult(nodeChild->getContentSize(), usedScale)); } else if(!nodeChild->getChildren().empty())//Panel { nodeChild->setScaleX(nodeChild->getScaleX() / usedScale); nodeChild->setScaleY(nodeChild->getScaleY() / usedScale); nodeChild->setContentSize(SizeMult(nodeChild->getContentSize(), usedScale)); //For depth 2 and more, the algorithm is the same resizeChildren(parentNode, nodeChild, usedScale, 2); } } } } Panel* parent = NULL; if(inPanel != NULL) { myNode->setContentSize(Size(0, 0)); parent = GraphicLayer::sharedLayer()->createPanelWithNode(inPanel, myNode, zIndex); } loadNodeToFenneX(myNode, parent); reorderZindex(); linkInputLabels(); animManagers.push_back(ccbReader->getAnimationManager()); ccbReader->release(); #if VERBOSE_PERFORMANCE_TIME timeval endTime; gettimeofday(&endTime, NULL); CCLOG("Node %s loaded to FenneX in %f ms, total with load file : %f ms", file, getTimeDifferenceMS(middleTime, endTime), getTimeDifferenceMS(startTime, endTime)); #endif return parent; }