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

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 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

热血枫叶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值