美文网首页
给Cocos2dx项目添加FGUI

给Cocos2dx项目添加FGUI

作者: porridgechen890 | 来源:发表于2021-10-27 20:58 被阅读0次

    win32平台

    1. 用cocos2dx 3.17.2 创建一个空工程。

      • void updateBMFontScale();加上virtual。
    2. 把libfairygui文件夹拷贝到cocos2d/cocos/editor-support/这个目录下。

    3. 添加项目。

      • 错误:无法读取项目文件libfairygui.vcxproj...因为那个路径是fgui官方示例的路径,我们需要改一下。
      <Import Project="..\..\Examples\cocos2d\cocos\2d\cocos2dx.props" />
      <Import Project="..\..\Examples\cocos2d\cocos\2d\cocos2d_headers.props" />
      <Import Project="..\..\Examples\cocos2d\cocos\2d\cocos2dx.props" />
      <Import Project="..\..\Examples\cocos2d\cocos\2d\cocos2d_headers.props" />
      

      改成:

      <Import Project="..\..\..\..\..\cocos2d\cocos\2d\cocos2dx.props" />
      <Import Project="..\..\..\..\..\cocos2d\cocos\2d\cocos2d_headers.props" />
      <Import Project="..\..\..\..\..\cocos2d\cocos\2d\cocos2dx.props" />
      <Import Project="..\..\..\..\..\cocos2d\cocos\2d\cocos2d_headers.props" />
      
    4. 生成项目。

      • 把不可用的平台工具集给改掉。
      • void GLoader3D::onChangeSpine()注释掉。
    5. 拷贝Classes和Resources。

      • 启动项目右键->生成依赖项->项目依赖项->勾上libfairygui。
      • 启动项目右键->属性->C/C++->常规->附加包含目录$(EngineRoot)cocos\editor-support\libfairygui\Classes
      • 启动项目右键->属性->链接器->输入->附加依赖项libfairygui.lib

    android平台

    1. 修改fgui的CMakeLists.txt。

      set(FAIRYGUI_HEADER
      editor-support/libfairygui/Classes/Controller.h
      editor-support/libfairygui/Classes/controller_action/ChangePageAction.h
      editor-support/libfairygui/Classes/controller_action/ControllerAction.h
      editor-support/libfairygui/Classes/controller_action/PlayTransitionAction.h
      editor-support/libfairygui/Classes/display/BitmapFont.h
      editor-support/libfairygui/Classes/display/FUIContainer.h
      editor-support/libfairygui/Classes/display/FUIInput.h
      editor-support/libfairygui/Classes/display/FUILabel.h
      editor-support/libfairygui/Classes/display/FUIRichText.h
      editor-support/libfairygui/Classes/display/FUISprite.h
      editor-support/libfairygui/Classes/display/TextFormat.h
      editor-support/libfairygui/Classes/DragDropManager.h
      editor-support/libfairygui/Classes/event/EventContext.h
      editor-support/libfairygui/Classes/event/HitTest.h
      editor-support/libfairygui/Classes/event/InputEvent.h
      editor-support/libfairygui/Classes/event/InputProcessor.h
      editor-support/libfairygui/Classes/event/UIEventDispatcher.h
      editor-support/libfairygui/Classes/event/UIEventType.h
      editor-support/libfairygui/Classes/FairyGUI.h
      editor-support/libfairygui/Classes/FairyGUIMacros.h
      editor-support/libfairygui/Classes/FieldTypes.h
      editor-support/libfairygui/Classes/GButton.h
      editor-support/libfairygui/Classes/GComboBox.h
      editor-support/libfairygui/Classes/GComponent.h
      editor-support/libfairygui/Classes/gears/GearAnimation.h
      editor-support/libfairygui/Classes/gears/GearBase.h
      editor-support/libfairygui/Classes/gears/GearColor.h
      editor-support/libfairygui/Classes/gears/GearDisplay.h
      editor-support/libfairygui/Classes/gears/GearDisplay2.h
      editor-support/libfairygui/Classes/gears/GearFontSize.h
      editor-support/libfairygui/Classes/gears/GearIcon.h
      editor-support/libfairygui/Classes/gears/GearLook.h
      editor-support/libfairygui/Classes/gears/GearSize.h
      editor-support/libfairygui/Classes/gears/GearText.h
      editor-support/libfairygui/Classes/gears/GearXY.h
      editor-support/libfairygui/Classes/GGraph.h
      editor-support/libfairygui/Classes/GGroup.h
      editor-support/libfairygui/Classes/GImage.h
      editor-support/libfairygui/Classes/GLabel.h
      editor-support/libfairygui/Classes/GList.h
      editor-support/libfairygui/Classes/GLoader.h
      editor-support/libfairygui/Classes/GLoader3D.h
      editor-support/libfairygui/Classes/GMovieClip.h
      editor-support/libfairygui/Classes/GObject.h
      editor-support/libfairygui/Classes/GObjectPool.h
      editor-support/libfairygui/Classes/GProgressBar.h
      editor-support/libfairygui/Classes/GRichTextField.h
      editor-support/libfairygui/Classes/GRoot.h
      editor-support/libfairygui/Classes/GScrollBar.h
      editor-support/libfairygui/Classes/GSlider.h
      editor-support/libfairygui/Classes/GTextField.h
      editor-support/libfairygui/Classes/GTextInput.h
      editor-support/libfairygui/Classes/GTree.h
      editor-support/libfairygui/Classes/GTreeNode.h
      editor-support/libfairygui/Classes/Margin.h
      editor-support/libfairygui/Classes/PackageItem.h
      editor-support/libfairygui/Classes/PopupMenu.h
      editor-support/libfairygui/Classes/RelationItem.h
      editor-support/libfairygui/Classes/Relations.h
      editor-support/libfairygui/Classes/ScrollPane.h
      editor-support/libfairygui/Classes/Transition.h
      editor-support/libfairygui/Classes/TranslationHelper.h
      editor-support/libfairygui/Classes/tween/EaseManager.h
      editor-support/libfairygui/Classes/tween/EaseType.h
      editor-support/libfairygui/Classes/tween/GPath.h
      editor-support/libfairygui/Classes/tween/GTween.h
      editor-support/libfairygui/Classes/tween/GTweener.h
      editor-support/libfairygui/Classes/tween/TweenManager.h
      editor-support/libfairygui/Classes/tween/TweenPropType.h
      editor-support/libfairygui/Classes/tween/TweenValue.h
      editor-support/libfairygui/Classes/UIConfig.h
      editor-support/libfairygui/Classes/UIObjectFactory.h
      editor-support/libfairygui/Classes/UIPackage.h
      editor-support/libfairygui/Classes/utils/ByteBuffer.h
      editor-support/libfairygui/Classes/utils/html/HtmlElement.h
      editor-support/libfairygui/Classes/utils/html/HtmlObject.h
      editor-support/libfairygui/Classes/utils/html/HtmlParser.h
      editor-support/libfairygui/Classes/utils/ToolSet.h
      editor-support/libfairygui/Classes/utils/UBBParser.h
      editor-support/libfairygui/Classes/utils/WeakPtr.h
      editor-support/libfairygui/Classes/Window.h
      )
      
      set(FAIRYGUI_SRC
      editor-support/libfairygui/Classes/Controller.cpp
      editor-support/libfairygui/Classes/controller_action/ChangePageAction.cpp
      editor-support/libfairygui/Classes/controller_action/ControllerAction.cpp
      editor-support/libfairygui/Classes/controller_action/PlayTransitionAction.cpp
      editor-support/libfairygui/Classes/display/BitmapFont.cpp
      editor-support/libfairygui/Classes/display/FUIContainer.cpp
      editor-support/libfairygui/Classes/display/FUIInput.cpp
      editor-support/libfairygui/Classes/display/FUILabel.cpp
      editor-support/libfairygui/Classes/display/FUIRichText.cpp
      editor-support/libfairygui/Classes/display/FUISprite.cpp
      editor-support/libfairygui/Classes/display/TextFormat.cpp
      editor-support/libfairygui/Classes/DragDropManager.cpp
      editor-support/libfairygui/Classes/event/EventContext.cpp
      editor-support/libfairygui/Classes/event/HitTest.cpp
      editor-support/libfairygui/Classes/event/InputEvent.cpp
      editor-support/libfairygui/Classes/event/InputProcessor.cpp
      editor-support/libfairygui/Classes/event/UIEventDispatcher.cpp
      editor-support/libfairygui/Classes/GButton.cpp
      editor-support/libfairygui/Classes/GComboBox.cpp
      editor-support/libfairygui/Classes/GComponent.cpp
      editor-support/libfairygui/Classes/gears/GearAnimation.cpp
      editor-support/libfairygui/Classes/gears/GearBase.cpp
      editor-support/libfairygui/Classes/gears/GearColor.cpp
      editor-support/libfairygui/Classes/gears/GearDisplay.cpp
      editor-support/libfairygui/Classes/gears/GearDisplay2.cpp
      editor-support/libfairygui/Classes/gears/GearFontSize.cpp
      editor-support/libfairygui/Classes/gears/GearIcon.cpp
      editor-support/libfairygui/Classes/gears/GearLook.cpp
      editor-support/libfairygui/Classes/gears/GearSize.cpp
      editor-support/libfairygui/Classes/gears/GearText.cpp
      editor-support/libfairygui/Classes/gears/GearXY.cpp
      editor-support/libfairygui/Classes/GGraph.cpp
      editor-support/libfairygui/Classes/GGroup.cpp
      editor-support/libfairygui/Classes/GImage.cpp
      editor-support/libfairygui/Classes/GLabel.cpp
      editor-support/libfairygui/Classes/GList.cpp
      editor-support/libfairygui/Classes/GLoader.cpp
      editor-support/libfairygui/Classes/GLoader3D.cpp
      editor-support/libfairygui/Classes/GMovieClip.cpp
      editor-support/libfairygui/Classes/GObject.cpp
      editor-support/libfairygui/Classes/GObjectPool.cpp
      editor-support/libfairygui/Classes/GProgressBar.cpp
      editor-support/libfairygui/Classes/GRichTextField.cpp
      editor-support/libfairygui/Classes/GRoot.cpp
      editor-support/libfairygui/Classes/GScrollBar.cpp
      editor-support/libfairygui/Classes/GSlider.cpp
      editor-support/libfairygui/Classes/GTextField.cpp
      editor-support/libfairygui/Classes/GTextInput.cpp
      editor-support/libfairygui/Classes/GTree.cpp
      editor-support/libfairygui/Classes/GTreeNode.cpp
      editor-support/libfairygui/Classes/Margin.cpp
      editor-support/libfairygui/Classes/PackageItem.cpp
      editor-support/libfairygui/Classes/PopupMenu.cpp
      editor-support/libfairygui/Classes/RelationItem.cpp
      editor-support/libfairygui/Classes/Relations.cpp
      editor-support/libfairygui/Classes/ScrollPane.cpp
      editor-support/libfairygui/Classes/Transition.cpp
      editor-support/libfairygui/Classes/TranslationHelper.cpp
      editor-support/libfairygui/Classes/tween/EaseManager.cpp
      editor-support/libfairygui/Classes/tween/GPath.cpp
      editor-support/libfairygui/Classes/tween/GTween.cpp
      editor-support/libfairygui/Classes/tween/GTweener.cpp
      editor-support/libfairygui/Classes/tween/TweenManager.cpp
      editor-support/libfairygui/Classes/tween/TweenPropType.cpp
      editor-support/libfairygui/Classes/tween/TweenValue.cpp
      editor-support/libfairygui/Classes/UIConfig.cpp
      editor-support/libfairygui/Classes/UIObjectFactory.cpp
      editor-support/libfairygui/Classes/UIPackage.cpp
      editor-support/libfairygui/Classes/utils/ByteBuffer.cpp
      editor-support/libfairygui/Classes/utils/html/HtmlElement.cpp
      editor-support/libfairygui/Classes/utils/html/HtmlObject.cpp
      editor-support/libfairygui/Classes/utils/html/HtmlParser.cpp
      editor-support/libfairygui/Classes/utils/ToolSet.cpp
      editor-support/libfairygui/Classes/utils/UBBParser.cpp
      editor-support/libfairygui/Classes/utils/WeakPtr.cpp
      editor-support/libfairygui/Classes/Window.cpp
      )
      
    2. 修改cocos2d的CMakeLists.txt。

      //省略
      
      option(BUILD_EDITOR_SPINE "Build editor support for spine" ON)
      option(BUILD_EDITOR_FGUI "Build editor support for fgui" ON)//增加
      option(BUILD_EXTENSIONS "Build extension library" ON)
      
      //省略
      
      if(BUILD_EDITOR_SPINE)
          include(editor-support/spine/CMakeLists.txt)
          set(COCOS_EDITOR_SUPPORT_SRC ${COCOS_EDITOR_SUPPORT_SRC} ${COCOS_SPINE_SRC} ${COCOS_SPINE_HEADER})
      endif(BUILD_EDITOR_SPINE)
      
      if(BUILD_EDITOR_FGUI)
          include(editor-support/libfairygui/CMakeLists.txt)
          set(COCOS_EDITOR_SUPPORT_SRC ${COCOS_EDITOR_SUPPORT_SRC} ${FAIRYGUI_SRC} ${FAIRYGUI_HEADER})//增加
      endif(BUILD_EDITOR_FGUI)
      
      if(BUILD_EXTENSIONS)
          include(../extensions/CMakeLists.txt)
      endif(BUILD_EXTENSIONS)
      
      //省略
      
      target_include_directories(cocos2d
          PUBLIC ${COCOS2DX_ROOT_PATH}
          PUBLIC ${COCOS2DX_ROOT_PATH}/cocos
          PUBLIC ${COCOS2DX_ROOT_PATH}/extensions
          PUBLIC ${COCOS2DX_ROOT_PATH}/cocos/platform
          PUBLIC ${COCOS2DX_ROOT_PATH}/cocos/editor-support/libfairygui/Classes//增加
          INTERFACE ${COCOS2DX_ROOT_PATH}/cocos/base
          INTERFACE ${COCOS2DX_ROOT_PATH}/cocos/editor-support
          INTERFACE ${COCOS2DX_ROOT_PATH}/cocos/audio/include
          INTERFACE ${COCOS2DX_ROOT_PATH}/cocos/platform/${PLATFORM_FOLDER}
      )
      
    3. 修改libfairygui/Classes/GRoot.cpp这个文件,把#include "AudioEngine.h"改成#include "audio/include/AudioEngine.h"

    4. 修改启动项目的CMakeLists.txt。

      # add cross-platforms source files and header files 
      list(APPEND GAME_SOURCE
          Classes/AppDelegate.cpp
          Classes/BagScene.cpp
          Classes/BagWindow.cpp
          Classes/BasicsScene.cpp
          Classes/ChatScene.cpp
          Classes/CooldownScene.cpp
          Classes/DemoScene.cpp
          Classes/EmojiParser.cpp
          Classes/GuideScene.cpp
          Classes/HitTestScene.cpp
          Classes/JoystickModule.cpp
          Classes/JoystickScene.cpp
          Classes/ListEffectScene.cpp
          Classes/LoopListScene.cpp
          Classes/MailItem.cpp
          Classes/MenuScene.cpp
          Classes/ModalWaitingScene.cpp
          Classes/PullToRefreshScene.cpp
          Classes/ScrollPaneScene.cpp
          Classes/TransitionDemoScene.cpp
          Classes/TreeViewScene.cpp
          Classes/VirtualListScene.cpp
          Classes/Window1.cpp
          Classes/Window2.cpp
          )
      list(APPEND GAME_HEADER
          Classes/AppDelegate.h
          Classes/BagScene.h
          Classes/BagWindow.h
          Classes/BasicsScene.h
          Classes/ChatScene.h
          Classes/CooldownScene.h
          Classes/DemoScene.h
          Classes/EmojiParser.h
          Classes/GuideScene.h
          Classes/HitTestScene.h
          Classes/JoystickModule.h
          Classes/JoystickScene.h
          Classes/ListEffectScene.h
          Classes/LoopListScene.h
          Classes/MailItem.h
          Classes/MenuScene.h
          Classes/ModalWaitingScene.h
          Classes/PullToRefreshScene.h
          Classes/ScrollPaneScene.h
          Classes/TransitionDemoScene.h
          Classes/TreeViewScene.h
          Classes/VirtualListScene.h
          Classes/Window1.h
          Classes/Window2.h
          )
      
      target_link_libraries(${APP_NAME} cocos2d)
      target_include_directories(${APP_NAME}
              PRIVATE Classes
              PRIVATE ${COCOS2DX_ROOT_PATH}/cocos/audio/include/
              PRIVATE ${COCOS2DX_ROOT_PATH}/cocos/editor-support/libfairygui/Classes/
      )
      

    相关文章

      网友评论

          本文标题:给Cocos2dx项目添加FGUI

          本文链接:https://www.haomeiwen.com/subject/ghopaltx.html