cocos2dx 3.1從零學習(六)——CocosStudio(VS2013工程導入及環境設置)

導入libCocosStudio、libExtensions、libGUI

新建的工程如下圖:


添加現有項目

右鍵解決方案,如下操作:


分別添加以下三個項目:

(工程路徑)\cocos2d\cocos\ui\proj.win32\libGUI.vcxproj

(工程路徑)\cocos2d\cocos\editor-support\cocostudio\proj.win32\libCocosStudio.vcxproj

(工程路徑)\cocos2d\extensions\proj.win32\libExtensions.vcxproj

完成後如圖:



添加引用:





添加 附加包含目錄,防止引入不了頭文件:


需要有:

$(EngineRoot)cocos\editor-support
$(EngineRoot)cocos
$(EngineRoot)cocos\audio\include
$(EngineRoot)external
$(EngineRoot)external\chipmunk\include\chipmunk
$(EngineRoot)extensions
$(EngineRoot)
..\Classes


編譯代碼!

編譯錯誤及解決方案:

1. 編輯器未更新

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB8020: The build tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, please install Visual Studio 2010 build tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Upgrade Solution...".
在新添加的項目 右鍵更新VC++編譯器。注意報這種錯的項目名稱右邊會有(VS2010***)的提示,就更新吧!


使用cocosstudio導出的工程。

#include "cocos2d.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
using namespace cocos2d;
using namespace cocostudio;
using namespace ui;


新手通過json文件讀取控件的時候,注意它們的父子關係,不然會崩潰。

    //加載CocosStudio導出的資源
    auto uiLayer = GUIReader::getInstance()->widgetFromJsonFile("StartUI/StartUI.ExportJson");
    this->addChild(uiLayer);

    auto bg = uiLayer->getChildByName("bg");
    auto button =(Button *) bg->getChildByName("button");
    button->runAction(MoveBy::create(1, Point(-111, 0)));
    button->addTouchEventListener(this, toucheventselector(CocosStudio::onButton) );

編譯錯誤及解決方案:

using namespace ui; 報錯的話,在前面加上using namespace cocos2d ;就可以了。

發佈了63 篇原創文章 · 獲贊 56 · 訪問量 25萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章