CocoStudio教程三:認識並利用CocoStudio的果實 運行2.2.1版本

原文:CocoStudio教程三:認識並利用CocoStudio的果實 

 

原文用的老版,用2.21搞起來好像有些問題,而後本身摸索了下,有的都是亂找的方法,只求能運行。。。php

1,原文的CCJsonReader方法新版本已改名爲CCSSceneReader!  好像新版去掉了前面的CC 改成SceneReaderjson

2,getIsLoop getRender都沒有找到,只能換成其餘方法了。isLoop和getNode;ide

運行成功,關鍵版本更新改變差別這麼大,堪憂~工具

 

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);

   

    UILayer* uiLayer=UILayer::create();
    auto myLayer=dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile("UIEditorTest_1/UIEditorTest_1.Json"));
    uiLayer->addWidget(myLayer);
    this->addChild(uiLayer);//默認z-order 0

    //首先讀取png,plist和ExportJson/json文件, 
    CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("ActionEditor/Cowboy0.png", "ActionEditor/Cowboy0.plist", "ActionEditor/Cowboy.ExportJson"); 
    //而後建立armature類,並將進行初始化 
    CCArmature *armature = CCArmature::create("Cowboy"); 
    //而後選擇播放動畫0,並進行縮放和位置設置 
    armature->getAnimation()->playByIndex(1); 
    //該模板中共製做了三個動畫,你能夠將索引修改成0/1/2中的任意值來查看不一樣效果 
    armature->setScale(0.5f); 
    armature->setPosition(ccp(visibleSize.width * 0.5, visibleSize.height * 0.5)); 
    //最後將armature添加到場景中 
    this->addChild(armature,2); 



    return true;
}



void HelloWorld::menuCloseCallback(CCObject* pSender)
{
    CCScene* newscene=CCScene::create();

    CCNode* pNode=SceneReader::sharedSceneReader()->createNodeWithSceneFile("SceneEditorTest/SceneEditorTest.json");

    //播放背景音樂 
    
    CCComAudio *pAudio = (CCComAudio*)(pNode->getComponent("Audio")); 
    pAudio->playBackgroundMusic(pAudio->getFile(), pAudio->isLoop()); 
    //給蝴蝶魚配置動畫 
    CCComRender *pFishRender = (CCComRender*)(pNode->getChildByTag(10010)->getComponent( "butterFlyFish")); 
    CCArmature *pButterFlyFish= (CCArmature *)(pFishRender->getNode()); 
    pButterFlyFish->getAnimation()->playByIndex(0); 
    newscene->addChild(pNode, 0, 1); 

    //newscene->addChild(uiLayer);
    //切換到新的場景 

    CCDirector::sharedDirector()->replaceScene(newscene);
}
View Code

 

 Cocos2d-x初入學堂(3)-->TexturePacker很是棒的圖像處理工具oop

CCSpriteBatchNode *spriteBatch = CCSpriteBatchNode::batchNodeWithTexture(texture);
改成CCSpriteBatchNode* spriteBatch=CCSpriteBatchNode::createWithTexture(textrue);動畫

相關文章
相關標籤/搜索