cocos2d-x 3.x Spine 3.7編譯環(huán)境配置

本篇基于

一.環(huán)境配置

下載cocos2d

git clone https://github.com/cocos2d/cocos2d-x.git
cd cocos2d-x
git checkout cocos2d-x-3.17.1
git submodule update --init

克隆存儲庫后,執(zhí)行download-deps.py下載并安裝依賴項。

python download-deps.py

接著執(zhí)行

python setup.py

配置環(huán)境變量,這將會配置cocos運行環(huán)境


環(huán)境變量
驗證cocos

打開cmd命令 執(zhí)行cocos -v 查看環(huán)境是否配置成功,顯示如下則說明配置成功

cocos -v
克隆spine
git clone https://github.com/EsotericSoftware/spine-runtimes.git
cd spine-runtimes
git checkout 3.7
git submodule update --init

二.創(chuàng)建項目

使用如下命令創(chuàng)建cocos項目

cocos new 項目名稱 -p (iOS bundle id或Android包名) -l cpp -d 存儲位置路徑

等待項目創(chuàng)建成功


Create Project

替換編譯文件

由于cocos2dx自帶的spine運行庫可能較老和spine版本不匹配,官方建議手動替換

The setup for cocos2d-x differs from most other Spine Runtimes because the cocos2d-x distribution includes a copy of the Spine Runtime files. This is not ideal because these files may be old and fail to work with the latest Spine editor. Also it means if cocos2d-x is updated, you may get newer Spine Runtime files which can break your application if you are not using the latest Spine editor. For these reasons, we have requested cocos2d-x to cease distributing the Spine Runtime files, but they continue to do so. The following instructions allow you to use the official Spine cocos2d-x runtime with your cocos2d-x project.

替換
  • 首先刪除 MyGame\cocos2d\cocos\editor-support\spine文件夾內(nèi)所有內(nèi)容
  • 復(fù)制
    spine-runtimes\spine-cpp\spine-cpp\include\spine
    spine-runtimes\spine-cpp\spine-cpp\src\spine
    spine-runtimes\spine-cocos2dx\src\spine
    下所有內(nèi)容至
    MyGame\cocos2d\cocos\editor-support\spine
  • 接著在 MyGame\cocos2d\cocos\editor-support\spine 文件夾下新建文件
    CMakeLists.txt 并寫入以下內(nèi)容
include_directories(editor-support)

file(GLOB_RECURSE COCOS_SPINE_SRC
    ${CMAKE_CURRENT_LIST_DIR}/*.cpp
    ${CMAKE_CURRENT_LIST_DIR}/**/*.cpp
)
file(GLOB_RECURSE COCOS_SPINE_HEADER
    ${CMAKE_CURRENT_LIST_DIR}/*.h
    ${CMAKE_CURRENT_LIST_DIR}/**/*.h
)
替換spine源碼示例
  • 復(fù)制 spine-runtimes\spine-cocos2dx\example\Classes 至 MyGame\Classes
  • 復(fù)制 spine-runtimes\spine-cocos2dx\example\Resources\common 至 MyGame\Resources\common
配置運行環(huán)境
  • 打開 /MyGame/proj.android/local.properties 文件
    配置ndk路徑
    ndk.dir=..\sdk\ndk\20.0.5594570

由于使用的ndk版本較高所以還需要修改以下位置

list(APPEND GAME_SOURCE
     Classes/AppDelegate.cpp
     Classes/HelloWorldScene.cpp
     )
list(APPEND GAME_HEADER
     Classes/AppDelegate.h
     Classes/HelloWorldScene.h
     )

修改為

list(APPEND GAME_SOURCE
         Classes/AppDelegate.cpp
         Classes/BatchingExample.cpp
         Classes/CoinExample.cpp
         Classes/GoblinsExample.cpp
         Classes/RaptorExample.cpp
         Classes/SkeletonRendererSeparatorExample.cpp
         Classes/SpineboyExample.cpp
         Classes/TankExample.cpp
     )
list(APPEND GAME_HEADER
         Classes/AppDelegate.h
         Classes/AppMacros.h
         Classes/BatchingExample.h
         Classes/CoinExample.h
         Classes/GoblinsExample.h
         Classes/RaptorExample.h
         Classes/SkeletonRendererSeparatorExample.h
         Classes/SpineboyExample.h
         Classes/TankExample.h
     )

編譯運行

使用Android Studio 打開 MyGame\proj.android
執(zhí)行 sync project 等待編譯完成,然后 run

或者使用命令編譯運行,切換至項目根目錄執(zhí)行

cocos compile -p android -m release -j 2

運行效果

效果
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容