// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); ///////////////////////////// // 3. add your codes below... CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("hero/Hero.ExportJson"); CCArmature* armature = CCArmature::create("Hero"); armature->getAnimation()->play("attack"); armature->setScale(1.5); armature->setPosition(ccp(visibleSize.width*0.25, visibleSize.height*0.25)); addChild(armature); return true; }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } m_fTime = 0.0f; m_bStart = false; m_bDead = false; m_fPercentage = 100.0f; m_fSpeed = 4.0f; m_fAttackDis = 120.0f; m_pGameScene = NULL; CCNode *pGameScene = SceneReader::sharedSceneReader()->createNodeWithSceneFile("FightScene.json"); m_pGameScene = pGameScene; this->addChild(pGameScene); CCComRender *render = (CCComRender*)(m_pGameScene->getChildByTag(10005)->getComponent("CCArmature")); CCArmature *pArmature = (CCArmature*)(render->getNode()); pArmature->getAnimation()->play("run"); m_bStart = true; CCMenuItemFont *itemBack = CCMenuItemFont::create("End", this, menu_selector(HelloWorld::menuCloseCallback)); itemBack->setColor(ccc3(255, 255, 255)); itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); CCMenu *menuBack = CCMenu::create(itemBack, NULL); menuBack->setPosition(CCPointZero); menuBack->setZOrder(4); this->addChild(menuBack); scheduleUpdate(); return true; }
bool CCComRender::serialize(void* r) { bool bRet = false; do { CC_BREAK_IF(r == NULL); SerData *pSerData = (SerData *)(r); const rapidjson::Value *v = pSerData->prData; stExpCocoNode *pCocoNode = pSerData->pCocoNode; const char *pClassName = NULL; const char *pComName = NULL; const char *pFile = NULL; const char *pPlist = NULL; std::string strFilePath; std::string strPlistPath; int nResType = 0; if (v != NULL) { pClassName = DICTOOL->getStringValue_json(*v, "classname"); CC_BREAK_IF(pClassName == NULL); pComName = DICTOOL->getStringValue_json(*v, "name"); const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData"); CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData)); pFile = DICTOOL->getStringValue_json(fileData, "path"); pPlist = DICTOOL->getStringValue_json(fileData, "plistFile"); CC_BREAK_IF(pFile == NULL && pPlist == NULL); nResType = DICTOOL->getIntValue_json(fileData, "resourceType", -1); } else if(pCocoNode != NULL) { pClassName = pCocoNode[1].GetValue(); CC_BREAK_IF(pClassName == NULL); pComName = pCocoNode[2].GetValue(); stExpCocoNode *pfileData = pCocoNode[4].GetChildArray(); CC_BREAK_IF(!pfileData); pFile = pfileData[0].GetValue(); pPlist = pfileData[1].GetValue(); CC_BREAK_IF(pFile == NULL && pPlist == NULL); nResType = atoi(pfileData[2].GetValue()); } if (pComName != NULL) { setName(pComName); } else { setName(pClassName); } if (pFile != NULL) { strFilePath.assign(cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename(pFile)); } if (pPlist != NULL) { strPlistPath.assign(cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename(pPlist)); } if (nResType == 0) { if (strcmp(pClassName, "CCSprite") == 0 && (strFilePath.find(".png") != strFilePath.npos || strFilePath.find(".pvr.ccz") != strFilePath.npos)) { m_pRender = CCSprite::create(strFilePath.c_str()); m_pRender->retain(); bRet = true; } else if(strcmp(pClassName, "CCTMXTiledMap") == 0 && strFilePath.find(".tmx") != strFilePath.npos) { m_pRender = CCTMXTiledMap::create(strFilePath.c_str()); m_pRender->retain(); bRet = true; } else if(strcmp(pClassName, "CCParticleSystemQuad") == 0 && strFilePath.find(".plist") != strFilePath.npos) { m_pRender = CCParticleSystemQuad::create(strFilePath.c_str()); m_pRender->setPosition(ccp(0.0f, 0.0f)); m_pRender->retain(); bRet = true; } else if(strcmp(pClassName, "CCArmature") == 0) { std::string file_extension = strFilePath; size_t pos = strFilePath.find_last_of('.'); if (pos != std::string::npos) { file_extension = strFilePath.substr(pos, strFilePath.length()); std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper); } if (file_extension == ".JSON" || file_extension == ".EXPORTJSON") { rapidjson::Document doc; if(!readJson(strFilePath.c_str(), doc)) { CCLog("read json file[%s] error!\n", strFilePath.c_str()); continue; } const rapidjson::Value &subData = DICTOOL->getDictionaryFromArray_json(doc, "armature_data", 0); const char *name = DICTOOL->getStringValue_json(subData, "name"); CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo(strFilePath.c_str()); CCArmature *pAr = CCArmature::create(name); m_pRender = pAr; m_pRender->retain(); const char *actionName = NULL; if (pCocoNode != NULL) { actionName = pCocoNode[6].GetValue();//DICTOOL->getStringValue_json(*v, "selectedactionname"); } else { actionName = DICTOOL->getStringValue_json(*v, "selectedactionname"); } if (actionName != NULL && pAr->getAnimation() != NULL) { pAr->getAnimation()->play(actionName); } bRet = true; } else if (file_extension == ".CSB") { unsigned long size = 0; unsigned char *pBytes = NULL; std::string binaryFilePath = CCFileUtils::sharedFileUtils()->fullPathForFilename(strFilePath.c_str()); pBytes = cocos2d::CCFileUtils::sharedFileUtils()->getFileData(binaryFilePath.c_str(), "rb", &size); CC_BREAK_IF(pBytes == NULL || strcmp((char*)pBytes, "") == 0); CocoLoader tCocoLoader; if (tCocoLoader.ReadCocoBinBuff((char*)pBytes)) { stExpCocoNode *tpRootCocoNode = tCocoLoader.GetRootCocoNode(); rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader); if (rapidjson::kObjectType == tType) { int count = tpRootCocoNode->GetChildNum(); stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray(); for (int i = 0; i < count; ++i) { std::string key = tpChildArray[i].GetName(&tCocoLoader); const char *str = tpChildArray[i].GetValue(); if (key.compare("armature_data") == 0) { int length = tpChildArray[i].GetChildNum(); stExpCocoNode *armature_dataArray = tpChildArray[i].GetChildArray(); if (length < 1) { continue; } length = armature_dataArray[0].GetChildNum(); stExpCocoNode *armature_data = armature_dataArray[0].GetChildArray(); for (int i = 0; i < length; ++i) { std::string key = armature_data[i].GetName(&tCocoLoader); const char *str = armature_data[i].GetValue(); if (key.compare("name") == 0) { if (str != NULL) { CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo(strFilePath.c_str()); CCArmature *pAr = CCArmature::create(str); m_pRender = pAr; m_pRender->retain(); const char *actionName = NULL; if (pCocoNode != NULL) { actionName = pCocoNode[6].GetValue();//DICTOOL->getStringValue_json(*v, "selectedactionname"); } else { actionName = DICTOOL->getStringValue_json(*v, "selectedactionname"); } if (actionName != NULL && pAr->getAnimation() != NULL) { pAr->getAnimation()->play(actionName); } bRet = true; } } } } } } } else { continue; } } else { continue; } } else if(strcmp(pClassName, "GUIComponent") == 0) { std::string file_extension = strFilePath; size_t pos = strFilePath.find_last_of('.'); if (pos != std::string::npos) { file_extension = strFilePath.substr(pos, strFilePath.length()); std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper); } if (file_extension == ".JSON" || file_extension == ".EXPORTJSON") { cocos2d::ui::TouchGroup* tg = cocos2d::ui::TouchGroup::create(); cocos2d::ui::Widget* widget = cocos2d::extension::GUIReader::shareReader()->widgetFromJsonFile(strFilePath.c_str()); tg->addWidget(widget); m_pRender = tg; m_pRender->retain(); bRet = true; } else if (file_extension == ".CSB") { cocos2d::ui::TouchGroup* tg = cocos2d::ui::TouchGroup::create(); cocos2d::ui::Widget* widget = cocos2d::extension::GUIReader::shareReader()->widgetFromBinaryFile(strFilePath.c_str()); tg->addWidget(widget); m_pRender = tg; m_pRender->retain(); bRet = true; } } else { CC_BREAK_IF(true); } } else if (nResType == 1) { if (strcmp(pClassName, "CCSprite") == 0) { std::string strPngFile = strPlistPath; std::string::size_type pos = strPngFile.find(".plist"); if (pos == strPngFile.npos) { continue; } strPngFile.replace(pos, strPngFile.length(), ".png"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(strPlistPath.c_str(), strPngFile.c_str()); m_pRender = CCSprite::createWithSpriteFrameName(strFilePath.c_str()); m_pRender->retain(); bRet = true; } else { CC_BREAK_IF(true); } } else { CC_BREAK_IF(true); } } while (0); return bRet; }
// on "init" you need to initialize your instance bool LayerChatWindow::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } lstStringMessage.clear(); lstStringMessage.push_back("Nhanh lên nào (14)!"); lstStringMessage.push_back("Mạng lag quá (9)!"); lstStringMessage.push_back("Bài xấu quá (3)!"); lstStringMessage.push_back("Hehe, lên nóc nhà\nmà bắt con gà (6)"); lstStringMessage.push_back("Nhất rồi, haha (1)"); lstStringMessage.push_back("Đánh gà thế (11)!"); lstStringMessage.push_back("Đỏ vãi lúa (13)!"); lstStringMessage.push_back("Nhọ như chó mực (5)!"); //return true; CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); _count = 100; layerButton = UILayer::create(); layerButton->addWidget(GUIReader::shareReader()->widgetFromJsonFile("LayerChatWindow_1.ExportJson")); this->addChild(layerButton); layerButton->setTouchPriority(-128); this->setTouchEnabled(true); //Get all chat button for( int i = 1; i <= 8; i++ ){ UIButton* btnChat = dynamic_cast<UIButton*>(layerButton->getWidgetByName( CCString::createWithFormat("btnChat%d", i)->getCString() )); btnChat->setTitleText( lstStringMessage.at(i-1).c_str() ); btnChat->addTouchEventListener(this,(SEL_TouchEvent)&LayerChatWindow::onButtonChats); } UIButton* btnClose = dynamic_cast<UIButton*>(layerButton->getWidgetByName("btnClose")); btnClose->addTouchEventListener(this,(SEL_TouchEvent)&LayerChatWindow::onButtonClose); // UIButton* btnSend = dynamic_cast<UIButton*>(layerButton->getWidgetByName("btnSend")); btnSend->addTouchEventListener(this,(SEL_TouchEvent)&LayerChatWindow::onButtonSend); txtChat = dynamic_cast<UITextField*>(layerButton->getWidgetByName("txtChat")); txtChat->setText(""); txtChat->setPlaceHolder("Noi dung"); txtChat->setTextHorizontalAlignment(kCCTextAlignmentCenter); txtChat->setTextVerticalAlignment(kCCVerticalTextAlignmentCenter); txtChat->addEventListenerTextField(this, textfieldeventselector(LayerChatWindow::textFieldEvent)); UIPanel* pEmo = dynamic_cast<UIPanel*>(layerButton->getWidgetByName("pEmo")); UIImageView* pImg = dynamic_cast<UIImageView*>(layerButton->getWidgetByName("Image_25_0")); //Add all emo to this int i = 1; // CCArmatureDataManager::sharedArmatureDataManager()->removeArmatureFileInfo(CCString::createWithFormat("onion%d.ExportJson", 1)->getCString()); // CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo(CCString::createWithFormat("onion%d.ExportJson", 1)->getCString()); int row=-1, col = 1; int widthOfPage = 580; int numOfCols = 9; int space = 10; int widthOfImage = 50; int startPosX = widthOfPage/2 - (widthOfImage+space)*numOfCols/2 - 300; int startPosY = space - 100; lstEmo.clear(); for( int i = 1; i<=16; i++ ){ CCArmature *armature = CCArmature::create(CCString::createWithFormat("onion%d", 1)->getCString()); armature->getAnimation()->playByIndex(i-1); RichElementCustomNode* recustom = RichElementCustomNode::create(1, ccWHITE, 255, armature); RichText* _richText = RichText::create(); _richText->setContentSize( armature->getContentSize() ); _richText->pushBackElement(recustom); if( col> numOfCols ){ row++; col = 1; } _richText->setAnchorPoint(ccp(0, 1)); _richText->setPosition(ccp( startPosX + 60*(col-1) , -1*row*50 - startPosY - (row+1)*space )); _richText->addTouchEventListener(this,(SEL_TouchEvent)&LayerChatWindow::OnEmoClick); lstEmo.push_back( armature ); UIButton* b = UIButton::create(); b->setPosition(ccp( startPosX + 60*(col-1) , -1*row*50 - startPosY - (row+1)*space )); b->setAnchorPoint(ccp(0, 1)); b->setContentSize( armature->getContentSize() ); b->addTouchEventListener(this,(SEL_TouchEvent)&LayerChatWindow::OnEmoClick); b->loadTextures("emo_blank.png", "", ""); b->setTag(i); pImg->addChild( _richText ); pImg->addChild( b ); //CCLOG("button w: %lf h: %lf", b->getContentSize().width, b->getContentSize().height); col++; } return true; }
bool CCComRender::serialize(void* r) { bool bRet = false; do { CC_BREAK_IF(r == NULL); rapidjson::Value *v = (rapidjson::Value *)r; const char *pClassName = DICTOOL->getStringValue_json(*v, "classname"); CC_BREAK_IF(pClassName == NULL); const char *pComName = DICTOOL->getStringValue_json(*v, "name"); if (pComName != NULL) { setName(pComName); } else { setName(pClassName); } const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData"); CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData)); const char *pFile = DICTOOL->getStringValue_json(fileData, "path"); const char *pPlist = DICTOOL->getStringValue_json(fileData, "plistFile"); CC_BREAK_IF(pFile == NULL && pPlist == NULL); std::string strFilePath; std::string strPlistPath; if (pFile != NULL) { strFilePath.assign(cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename(pFile)); } if (pPlist != NULL) { strPlistPath.assign(cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename(pPlist)); } int nResType = DICTOOL->getIntValue_json(fileData, "resourceType", -1); if (nResType == 0) { if (strcmp(pClassName, "CCSprite") == 0 && strFilePath.find(".png") != strFilePath.npos) { m_pRender = CCSprite::create(strFilePath.c_str()); } else if(strcmp(pClassName, "CCTMXTiledMap") == 0 && strFilePath.find(".tmx") != strFilePath.npos) { m_pRender = CCTMXTiledMap::create(strFilePath.c_str()); } else if(strcmp(pClassName, "CCParticleSystemQuad") == 0 && strFilePath.find(".plist") != strFilePath.npos) { m_pRender = CCParticleSystemQuad::create(strFilePath.c_str()); m_pRender->setPosition(ccp(0.0f, 0.0f)); } else if(strcmp(pClassName, "CCArmature") == 0) { std::string reDir = strFilePath; std::string file_path = ""; size_t pos = reDir.find_last_of('/'); if (pos != std::string::npos) { file_path = reDir.substr(0, pos+1); } rapidjson::Document doc; if(!readJson(strFilePath.c_str(), doc)) { CCLog("read json file[%s] error!\n", strFilePath.c_str()); continue; } const rapidjson::Value &subData = DICTOOL->getDictionaryFromArray_json(doc, "armature_data", 0); const char *name = DICTOOL->getStringValue_json(subData, "name"); CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo(strFilePath.c_str()); CCArmature *pAr = CCArmature::create(name); m_pRender = pAr; const char *actionName = DICTOOL->getStringValue_json(*v, "selectedactionname"); if (actionName != NULL && pAr->getAnimation() != NULL) { pAr->getAnimation()->play(actionName); } } else if(strcmp(pClassName, "GUIComponent") == 0) { cocos2d::gui::TouchGroup* tg = cocos2d::gui::TouchGroup::create(); cocos2d::gui::Widget* widget = cocos2d::extension::GUIReader::shareReader()->widgetFromJsonFile(strFilePath.c_str()); tg->addWidget(widget); m_pRender = tg; } else { CC_BREAK_IF(true); } } else if (nResType == 1) { if (strcmp(pClassName, "CCSprite") == 0) { std::string strPngFile = strPlistPath; std::string::size_type pos = strPngFile.find(".plist"); if (pos == strPngFile.npos) { continue; } strPngFile.replace(pos, strPngFile.length(), ".png"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(strPlistPath.c_str(), strPngFile.c_str()); m_pRender = CCSprite::createWithSpriteFrameName(strFilePath.c_str()); } else { CC_BREAK_IF(true); } } else { CC_BREAK_IF(true); } bRet = true; } while (0); return bRet; }
CCArmature* AnimLoader::createAnimation(const char *resName, const char *animName) { CCArmature *armature = CCArmature::create(resName); armature->getAnimation()->play(animName, 0, 0, -1, 0); return armature; }
CCNode* SceneReader::createObject(const rapidjson::Value &root, cocos2d::CCNode* parent) { const char *className = DICTOOL->getStringValue_json(root, "classname"); //inputFiles->getItemStringValue("classname"); if(strcmp(className, "CCNode") == 0) { CCNode* gb = NULL; if(NULL == parent) { gb = CCNode::create(); } else { gb = CCNode::create(); parent->addChild(gb); } setPropertyFromJsonDict(root, gb); int count = DICTOOL->getArrayCount_json(root, "components"); for (int i = 0; i < count; i++) { const rapidjson::Value &subDict = DICTOOL->getSubDictionary_json(root, "components", i); if (!DICTOOL->checkObjectExist_json(subDict)) { break; } const char *comName = DICTOOL->getStringValue_json(subDict, "classname"); const char *pComName = DICTOOL->getStringValue_json(subDict, "name"); const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(subDict, "fileData"); std::string pPath; std::string pPlistFile; int nResType = 0; //if (fileData != NULL) if (DICTOOL->checkObjectExist_json(fileData)) { const char *file = DICTOOL->getStringValue_json(fileData, "path"); nResType = DICTOOL->getIntValue_json(fileData, "resourceType", - 1); const char *plistFile = DICTOOL->getStringValue_json(fileData, "plistFile"); if (file != NULL) { pPath.append(cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename(file)); } if (plistFile != NULL) { pPlistFile.append(cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename(plistFile)); } } if (comName != NULL && strcmp(comName, "CCSprite") == 0) { cocos2d::CCSprite *pSprite = NULL; if (nResType == 0) { if (pPath.find(".png") == pPath.npos) { continue; } pSprite = CCSprite::create(pPath.c_str()); } else if (nResType == 1) { std::string pngFile = pPlistFile; std::string::size_type pos = pngFile.find(".plist"); if (pos == pPath.npos) { continue; } pngFile.replace(pos, pngFile.length(), ".png"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(pPlistFile.c_str(), pngFile.c_str()); pSprite = CCSprite::createWithSpriteFrameName(pPath.c_str()); } else { continue; } CCComRender *pRender = CCComRender::create(pSprite, "CCSprite"); if (pComName != NULL) { pRender->setName(pComName); } gb->addComponent(pRender); if (_pListener && _pfnSelector) { (_pListener->*_pfnSelector)(pSprite, (void*)(&subDict)); } } else if(comName != NULL && strcmp(comName, "CCTMXTiledMap") == 0) { cocos2d::CCTMXTiledMap *pTmx = NULL; if (nResType == 0) { if (pPath.find(".tmx") == pPath.npos) { continue; } pTmx = CCTMXTiledMap::create(pPath.c_str()); } else { continue; } CCComRender *pRender = CCComRender::create(pTmx, "CCTMXTiledMap"); if (pComName != NULL) { pRender->setName(pComName); } gb->addComponent(pRender); if (_pListener && _pfnSelector) { (_pListener->*_pfnSelector)(pTmx, (void*)(&subDict)); } } else if(comName != NULL && strcmp(comName, "CCParticleSystemQuad") == 0) { std::string::size_type pos = pPath.find(".plist"); if (pos == pPath.npos) { continue; } cocos2d::CCParticleSystemQuad *pParticle = NULL; if (nResType == 0) { pParticle = CCParticleSystemQuad::create(pPath.c_str()); } else { CCLog("unknown resourcetype on CCParticleSystemQuad!"); } pParticle->setPosition(0, 0); CCComRender *pRender = CCComRender::create(pParticle, "CCParticleSystemQuad"); if (pComName != NULL) { pRender->setName(pComName); } gb->addComponent(pRender); if (_pListener && _pfnSelector) { (_pListener->*_pfnSelector)(pParticle, (void*)(&subDict)); } } else if(comName != NULL && strcmp(comName, "CCArmature") == 0) { if (nResType != 0) { continue; } std::string reDir = pPath; std::string file_path = ""; size_t pos = reDir.find_last_of('/'); if (pos != std::string::npos) { file_path = reDir.substr(0, pos+1); } rapidjson::Document jsonDict; if(!readJson(pPath.c_str(), jsonDict)) { CCLog("read json file[%s] error!\n", pPath.c_str()); continue; } int childrenCount = DICTOOL->getArrayCount_json(jsonDict, "armature_data"); const rapidjson::Value &subData = DICTOOL->getDictionaryFromArray_json(jsonDict, "armature_data", 0); const char *name = DICTOOL->getStringValue_json(subData, "name"); childrenCount = DICTOOL->getArrayCount_json(jsonDict, "config_file_path"); for (int i = 0; i < childrenCount; ++i) { const char* plist = DICTOOL->getStringValueFromArray_json(jsonDict, "config_file_path", i); if (plist == NULL) { continue; } std::string plistpath; plistpath += file_path; plistpath.append(plist); cocos2d::CCDictionary *root = CCDictionary::createWithContentsOfFile(plistpath.c_str()); CCDictionary* metadata = DICTOOL->getSubDictionary(root, "metadata"); const char* textureFileName = DICTOOL->getStringValue(metadata, "textureFileName"); std::string textupath; textupath += file_path; textupath.append(textureFileName); CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo(textupath.c_str(), plistpath.c_str(), pPath.c_str()); } CCArmature *pAr = CCArmature::create(name); CCComRender *pRender = CCComRender::create(pAr, "CCArmature"); if (pComName != NULL) { pRender->setName(pComName); } gb->addComponent(pRender); const char *actionName = DICTOOL->getStringValue_json(subDict, "selectedactionname"); if (actionName != NULL && pAr->getAnimation() != NULL) { pAr->getAnimation()->play(actionName); } if (_pListener && _pfnSelector) { (_pListener->*_pfnSelector)(pAr, (void*)(&subDict)); } } else if(comName != NULL && strcmp(comName, "CCComAudio") == 0) { CCComAudio *pAudio = NULL; if (nResType == 0) { pAudio = CCComAudio::create(); } else { continue; } pAudio->preloadEffect(pPath.c_str()); gb->addComponent(pAudio); if (_pListener && _pfnSelector) { (_pListener->*_pfnSelector)(pAudio, (void*)(&subDict)); } } else if(comName != NULL && strcmp(comName, "CCComAttribute") == 0) { CCComAttribute *pAttribute = NULL; if (nResType == 0) { pAttribute = CCComAttribute::create(); unsigned long size = 0; const char* pData = 0; pData = (char*)(cocos2d::CCFileUtils::sharedFileUtils()->getFileData(pPath.c_str(), "r", &size)); if(pData != NULL && strcmp(pData, "") != 0) { pAttribute->parse(pData); } } else { CCLog("unknown resourcetype on CCComAttribute!"); continue; } gb->addComponent(pAttribute); if (_pListener && _pfnSelector) { (_pListener->*_pfnSelector)(pAttribute, (void*)(&subDict)); } } else if (comName != NULL && strcmp(comName, "CCBackgroundAudio") == 0) { CCComAudio *pAudio = NULL; if (nResType == 0) { pAudio = CCComAudio::create(); } else { continue; } #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) // no MP3 support for CC_PLATFORM_WP8 std::string::size_type pos = pPath.find(".mp3"); if (pos == pPath.npos) { continue; } pPath.replace(pos, pPath.length(), ".wav"); #endif pAudio->preloadBackgroundMusic(pPath.c_str()); pAudio->setFile(pPath.c_str()); bool bLoop = (bool)(DICTOOL->getIntValue_json(subDict, "loop")); pAudio->setLoop(bLoop); gb->addComponent(pAudio); if (_pListener && _pfnSelector) { (_pListener->*_pfnSelector)(pAudio, (void*)(&subDict)); } pAudio->playBackgroundMusic(pPath.c_str(), bLoop); } else if(comName != NULL && strcmp(comName, "GUIComponent") == 0) { cocos2d::extension::UILayer *pLayer = cocos2d::extension::UILayer::create(); pLayer->scheduleUpdate(); UIWidget* widget = cocos2d::extension::GUIReader::shareReader()->widgetFromJsonFile(pPath.c_str()); pLayer->addWidget(widget); CCComRender *pRender = CCComRender::create(pLayer, "GUIComponent"); if (pComName != NULL) { pRender->setName(pComName); } gb->addComponent(pRender); if (_pListener && _pfnSelector) { (_pListener->*_pfnSelector)(pLayer, (void*)(&subDict)); } } } int length = DICTOOL->getArrayCount_json(root, "gameobjects"); for (int i = 0; i < length; ++i) { const rapidjson::Value &subDict = DICTOOL->getSubDictionary_json(root, "gameobjects", i); if (!DICTOOL->checkObjectExist_json(subDict)) { break; } createObject(subDict, gb); } return gb; } return NULL; }
void EffectComponentTest::defaultPlay() { CCComRender *pRender = static_cast<CCComRender*>(m_rootNode->getChildByTag(10015)->getComponent("CCArmature")); CCArmature *pAr = static_cast<CCArmature*>(pRender->getNode()); pAr->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(EffectComponentTest::animationEvent)); }