原文:CocoStudio教程三:认识并利用CocoStudio的果实
原文用的老版,用2.21搞起来好像有些问题,然后自己摸索了下,有的都是乱找的方法,只求能运行。。。
1,原文的CCJsonReader方法新版本已更名为CCSSceneReader! 好像新版去掉了前面的CC 改为SceneReader
2,getIsLoop getRender都没有找到,只能换成其他方法了。isLoop和getNode;
运行成功,关键版本更新改变差异这么大,堪忧~
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); }
Cocos2d-x初入学堂(3)-->TexturePacker非常棒的图像处理工具
CCSpriteBatchNode *spriteBatch = CCSpriteBatchNode::batchNodeWithTexture(texture);
改为CCSpriteBatchNode* spriteBatch=CCSpriteBatchNode::createWithTexture(textrue);