cocos2d-x版本:3.x
cocostudio版本:1.6
说一些抱怨的话,cocos2d-x自3.0以后发生的变化可以用翻天覆地来形容都不为过,不但类名与2.x版本的不一样(不仅仅只是体现在去掉2.x版本的类名开头CC),一些类名甚至可以说全改了,对资源的解析也采取了不一样的方式,而网络上的技术贴很多都是2.x版本的,一旦出现问题,官网上的指导有时候都不管用,真是头大,坑特多,不知道为啥需要这么大的变化的,边学边记,碰到问题解决了就赶紧记下来吧,不然以后又被坑了。
闲话不说,开始正题!
cocos2d-x的英文官网我没有去看,只是看了中文官网的指导,原来想着ui界面的加载,那按照官网指导肯定是最权威,可是,就这样被坑了一下。
以下的内容是官方的指导:
将导出后的项目放到资源文件件中。(假设画布名称为“UIEditorTest_1”)
<div class="dp-Highlighter bg_cpp" style="font-family: Consolas,'Courier New',Courier,mono,serif; font-size: 12px; width: 659.328125px; overflow: auto; padding-top: 1px; margin: 18px 0px !important; background-color: rgb(231,229,220);"><div class="bar" style="padding-left: 45px;"><div class="tools" style="padding: 3px 8px 10px 10px; font-stretch: normal; font-size: 9px; line-height: normal; font-family: Verdana,Geneva,Helvetica,sans-serif; color: silver; border-left-width: 3px; border-left-style: solid; border-left-color: rgb(108,226,108); background-color: rgb(248,248,248);"><strong>[cpp]</strong> <a target=_blank href="http://blog.csdn.net/yangyunchenrt/article/details/39926367#" class="ViewSource" title="view plain" style="color: rgb(160,160,160); text-decoration: none; border: none; padding: 1px; margin: 0px 10px 0px 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); background-attachment: initial; background-color: inherit; background-size: initial; background-origin: initial; background-clip: initial; background-position: 0% 0%; background-repeat: no-repeat;">view plain</a><a target=_blank href="http://blog.csdn.net/yangyunchenrt/article/details/39926367#" class="CopyToClipboard" title="copy" style="color: rgb(160,160); text-decoration: none; border: none; padding: 1px; margin: 0px 10px 0px 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); background-attachment: initial; background-color: inherit; background-size: initial; background-origin: initial; background-clip: initial; background-position: 0% 0%; background-repeat: no-repeat;">copy</a><div style="position: absolute; left: 851px; top: 847px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1" class="dp-cpp" style="padding: 0px; border: none; color: rgb(92,92,92); margin: 0px 0px 1px 45px !important; background-color: rgb(255,255,255);"><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108,108); list-style: decimal-leading-zero outside; color: inherit; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0,130,0); background-color: inherit;">//根据文件创建一个界面</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"></span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108,108); list-style: decimal-leading-zero outside; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248,248);"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">TouchGroup*ul=TouchGroup::create();</span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108,108); list-style: decimal-leading-zero outside; color: inherit; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">ul->addWidget(GUIReader::shareReader()->widgetFromJsonFile(<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"UIEditorTest_1.json"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">));</span></span></li></ol></div><div class="dp-Highlighter bg_cpp" style="font-family: Consolas,160); text-decoration: none; border: none; padding: 1px; margin: 0px 10px 0px 0px; font-size: 9px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); background-attachment: initial; background-color: inherit; background-size: initial; background-origin: initial; background-clip: initial; background-position: 0% 0%; background-repeat: no-repeat;">copy</a><div style="position: absolute; left: 851px; top: 952px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1" class="dp-cpp" style="padding: 0px; border: none; color: rgb(92,0); background-color: inherit;">//根据tag获取一个控件</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"></span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108,248);"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">ul->getChildByTag(1);</span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108,108); list-style: decimal-leading-zero outside; color: inherit; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108,248);"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0,0); background-color: inherit;">//播放UI动画</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"></span></span></li><li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108,108); list-style: decimal-leading-zero outside; color: inherit; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">AnimationManager::shareManager()->getAnimationByName(<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"DemoHead_UI.json"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">,</span><span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"Animation0"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">)->play();</span></span></li></ol></div>
木有TouchGroup这个类有木有啊!
只有Touch类啊有木有啊!
Touch类不是我们要的有木有啊!!
说多了都是泪啊有木有啊!!!
好吧,没办法了,谁让咱要用人家呢,谁让别人家都是大爷呢!百度打开,Google打开(额,谷歌被墙了,没法用了,555...),只能百度了,TouchGroup不能用了,那用啥呢,有说Helper类,有说UILayer的(UILayer还是2.x时代的好不好撒,呜呜...),各种混乱,最后还是在官网论坛上找到了一点指导,说多了还是泪啊...
- Node*pNode=GUIReader::getInstance()->widgetFromJsonFile("test.ExportJson");
- this->addChild(pNode);
当时我的UI界面里头做了个头像跟血条,一说到血条,顺带说一个糗事,血条当时看到有本书上说可以用slider来做,然后我很自然的就:
copy