cocoStudio中的场景编辑器
定义:就是把UI交互、动画人物、物理模拟等元素融合起来,如图:
代码:
bool HelloWorld::init()
{
//
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
//初始化场景
CCNode *pFishJoyScene = SceneReader::sharedSceneReader()->createNodeWithSceneFile("FishJoy2.json");
this->addChild(pFishJoyScene);
//添加动画
cocos2d::extension::ActionManager::shareManager()->playActionByName("startMenu_1.json","Animation1");
//添加按钮
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);
return true;
}
这里还要补充下:
//常见一个新的场景
CCScene * newscene = CCScene::create();
//加载导出文件并初始化根节点
CCNode *pNode = SceneReader::sharedSceneReader()->createNodeWithSceneFile("SceneEditorTest/SceneEditorTest.json");
//通过tag获取音频组件
CCComAudio *pAudio = (CCComAudio*)(pNode->getComponent("Audio"));
//播放音频
pAudio->playBackgroundMusic(pAudio->getFile(), pAudio->isLoop());
//获取comrender组件
CCComRender *pFishRender = (CCComRender*)(pNode->getChildByTag(10010)->getComponent( "butterFlyFish"));
//转换为armature
CCArmature *pButterFlyFish= (CCArmature *)(pFishRender->getNode());
pButterFlyFish->getAnimation()->playByIndex(0);
//将根节点添加到新场景
newscene->addChild(pNode, 0, 1);
//切换场景
CCDirector::sharedDirector()->replaceScene(newscene);
有关场景使用,基本就这么多了。
示例资源及代码: https://github.com/chukong/CocoStudioSamples