bilalmirza

Hello,

Cocos2d-x v4 is almost in beta. I need to use it since it got metal support and I also need to use spine with it. Could you please merge the pr sent by cocos2d-x. So they can include spine support with it?

https://github.com/EsotericSoftware/spine-runtimes/pull/1244

Thanks!
bilalmirza
  • Posts: 28

badlogic

Our plan is to merge the PR once there's an official v4 release. You can clone our repository and merge the PR into your local repository copy in the meantime.
User avatar
badlogic

Mario
  • Posts: 1936

Roo101

In case anyone needs to support both Cocos2d-x v3 and v4, and doesn't want to use the CMakeLists.txt that's in the github repo which copies the spine source into the cocos2d/editor-support/spine folder, then this is a working script:
get_target_property(COCOS2D_X_VERSION cocos2d VERSION)

if (COCOS2D_X_VERSION VERSION_GREATER_EQUAL 4.0)
set(SPINE_COCOS_X_VERSION_DIR "v4")
else()
set(SPINE_COCOS_X_VERSION_DIR "v3")
endif()

set(SPINE_COCOS2DX_HEADER
${CMAKE_CURRENT_LIST_DIR}/${SPINE_COCOS_X_VERSION_DIR}/src/spine/AttachmentVertices.h
${CMAKE_CURRENT_LIST_DIR}/${SPINE_COCOS_X_VERSION_DIR}/src/spine/SkeletonAnimation.h
${CMAKE_CURRENT_LIST_DIR}/${SPINE_COCOS_X_VERSION_DIR}/src/spine/SkeletonBatch.h
${CMAKE_CURRENT_LIST_DIR}/${SPINE_COCOS_X_VERSION_DIR}/src/spine/SkeletonRenderer.h
${CMAKE_CURRENT_LIST_DIR}/${SPINE_COCOS_X_VERSION_DIR}/src/spine/SkeletonTwoColorBatch.h
${CMAKE_CURRENT_LIST_DIR}/${SPINE_COCOS_X_VERSION_DIR}/src/spine/spine-cocos2dx.h
)

set(SPINE_COCOS2DX_SRC
${CMAKE_CURRENT_LIST_DIR}/${SPINE_COCOS_X_VERSION_DIR}/src/spine/AttachmentVertices.cpp
${CMAKE_CURRENT_LIST_DIR}/${SPINE_COCOS_X_VERSION_DIR}/src/spine/SkeletonAnimation.cpp
${CMAKE_CURRENT_LIST_DIR}/${SPINE_COCOS_X_VERSION_DIR}/src/spine/SkeletonBatch.cpp
${CMAKE_CURRENT_LIST_DIR}/${SPINE_COCOS_X_VERSION_DIR}/src/spine/SkeletonRenderer.cpp
${CMAKE_CURRENT_LIST_DIR}/${SPINE_COCOS_X_VERSION_DIR}/src/spine/SkeletonTwoColorBatch.cpp
${CMAKE_CURRENT_LIST_DIR}/${SPINE_COCOS_X_VERSION_DIR}/src/spine/spine-cocos2dx.cpp
)

list(APPEND SPINE_COCOS2DX_SRC ${SPINE_COCOS2DX_HEADER})

add_library(spine-cocos2dx-static STATIC ${SPINE_COCOS2DX_SRC})

set_target_properties(spine-cocos2dx-static
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
)

add_dependencies(spine-cocos2dx-static spine-static cocos2d)

target_link_libraries(spine-cocos2dx-static
PUBLIC spine-static
PRIVATE cocos2d
)
target_include_directories(spine-cocos2dx-static PUBLIC ${CMAKE_CURRENT_LIST_DIR}/${SPINE_COCOS_X_VERSION_DIR}/src)
The folder structure is as follows:

gamename/external/spine/CMakeLists.txt (with the above script)
gamename/external/spine/v3/src/spine
gamename/external/spine/v4/src/spine

You may want to add the following to your root game CMakeLists.txt to get rid of the spine folder in the cocos2d/editor-support path (and avoid the header file errors):
execute_process(
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_CURRENT_SOURCE_DIR}/cocos2d/cocos/editor-support/spine"
)
Then to use the spine-cocos2dx-static lib, add the following to the gamename/CMakeLists.txt:
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/spine-cocos2dx ${PROJECT_BINARY_DIR}/spine-cocos2dx)
get_target_property(spine_cocos2dx_INCLUDE_DIRS spine-cocos2dx-static INTERFACE_INCLUDE_DIRECTORIES)

target_include_directories(${APP_NAME} PRIVATE spine_cocos2dx_INCLUDE_DIRS)
target_link_libraries(${APP_NAME} spine-cocos2dx-static)
Roo101
  • Posts: 19


Return to Runtimes