首页 > 其他 > 详细

从零开始学习cocoStudio(6)--场景

时间:2014-01-21 23:00:03      阅读:655      评论:0      收藏:0      [点我收藏+]

cocoStudio中的场景编辑器


      定义:就是把UI交互、动画人物、物理模拟等元素融合起来,如图:


bubuko.com,布布扣


代码:

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 

从零开始学习cocoStudio(6)--场景

原文:http://blog.csdn.net/rexuefengye/article/details/18600679

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!