cocos2d::CCNode* SceneEditorTestLayer::createGameScene()
{
    CCNode *pNode = CCJsonReader::sharedJsonReader()->createNodeWithJsonFile("FishJoy2.json");
	if (pNode == NULL)
	{
		return NULL;
	}
	m_pCurNode = pNode;

	//play back music
    CCComAudio *pAudio = (CCComAudio*)(pNode->getComponent("Audio"));
	pAudio->playBackgroundMusic(pAudio->getFile(), pAudio->getIsLoop());

	//fishes
	CCArmature *pBlowFish = getFish(5, "blowFish");
	CCArmature *pButterFlyFish = getFish(6, "butterFlyFish");
	pBlowFish->getAnimation()->playByIndex(0);
	pButterFlyFish->getAnimation()->playByIndex(0);

    CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(SceneEditorTestLayer::toExtensionsMainLayer));
        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);

    pNode->addChild(menuBack);
    
	//ui action
	cocos2d::extension::UIActionManager::shareManager()->PlayActionByName("startMenu_1.json","Animation1");

    return pNode;
}
Пример #2
0
void BackgroundComponentTest::defaultPlay()
{
	cocos2d::extension::ActionManager::getInstance()->playActionByName("startMenu_1.json","Animation1");

	CCComAudio *Audio = static_cast<CCComAudio*>(m_rootNode->getComponent("CCBackgroundAudio"));
	Audio->playBackgroundMusic();
}
Пример #3
0
bool GameOverScene::init()
{
	size = CCDirector::sharedDirector()->getVisibleSize();
	CCSprite *falseBg = CCSprite::create("shibaiditu.png");
	falseBg->setPosition(ccp(size.width/2,size.height/2));
	addChild(falseBg);
	CCSprite *buttonBg = CCSprite::create("continue_fight_text.png");
	Button *continuteButton = Button::create();
	continuteButton->addNode(buttonBg);
	continuteButton->setPosition(ccp(size.width/2,size.height/2));
	addChild(continuteButton);
    CCComAudio *pAudio = CCComAudio::create();
    pAudio->setFile("shibai.mp3");
    pAudio->playBackgroundMusic("shibai.mp3",true);
	return true;
}
Пример #4
0
void PlayMusic::done()
{
	do 
	{
		CCNode *pNode = SceneReader::sharedSceneReader()->getNodeByTag(_nTag);
		CC_BREAK_IF(pNode == NULL);
		CCComAudio *audio = (CCComAudio*)(pNode->getComponent(_comName.c_str()));
		CC_BREAK_IF(audio == NULL);
		if (_nType == 0)
		{
			audio->playBackgroundMusic();
		}
		else if (_nType == 1)
		{
			audio->playEffect();
		}

	} while (0);
}
Пример #5
0
	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;
    }