7.8 KiB
spine-cocos2dx v3.x
The spine-cocos2dx runtime provides functionality to load, manipulate and render Spine skeletal animation data using cocos2d-x. spine-cocos2dx is based on spine-cpp.
Licensing
You are welcome to evaluate the Spine Runtimes and the examples we provide in this repository free of charge.
You can integrate the Spine Runtimes into your software free of charge, but users of your software must have their own Spine license. Please make your users aware of this requirement! This option is often chosen by those making development tools, such as an SDK, game toolkit, or software library.
In order to distribute your software containing the Spine Runtimes to others that don't have a Spine license, you need a Spine license at the time of integration. Then you can distribute your software containing the Spine Runtimes however you like, provided others don't modify it or use it to create new software. If others want to do that, they'll need their own Spine license.
For the official legal terms governing the Spine Runtimes, please read the Spine Runtimes License Agreement and Section 2 of the Spine Editor License Agreement.
Spine version
spine-cocos2dx works with data exported from Spine 3.7.xx.
spine-cocos2dx supports all Spine features.
Setup
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.
- Create a new cocos2d-x project. See the cocos2d-x documentation
- Delete the folder
cocos2d/cocos/editor-support/spine. This will remove the outdated Spine cocos2d-x runtime shipped by cocos2d-x. - Open your project in your IDE of choice, then open the cocos2d_libs sub project and delete the
editor-support/spinegroup. This will remove the outdated Spine cocos2d-x runtime shipped by cocos2d-x from your build. - Download the Spine Runtimes source using git (
git clone https://github.com/esotericsoftware/spine-runtimes) or download it as a zip via the download button above. - Add the sources from
spine-cpp/spine-cpp/src/spineandspine-cocos2dx/src/spineto your project - Add the folders
spine-cpp/spine-cpp/includeandspine-cocos2dx/srcto your header search path. Note that includes are specified as#inclue <spine/file.h>, so thespinedirectory cannot be omitted when copying the source files.
Example
The Spine cocos2d-x example works on Windows, Mac OS X, iOS and Android.
Windows
- Install Visual Studio 2015 Community
- Install CMake via the Windows installer package.
- Download the Spine Runtimes repository using git (
git clone https://github.com/esotericsoftware/spine-runtimes) or download it as a zip via the download button above. - Run CMake GUI from the start menu
- Click
Browse Sourceand select the directoryspine-runtimes - Click
Browse Buildand select thespine-runtimes/spine-cocos2dx/builddirectory. You can create thebuildfolder directly in the file dialog viaNew Folder. - Click
Configure. This will download the cocos2d-x dependency and wire it up with the example source code inspine-runtimes/spine-cocos2dx/example. The download is 400mb, so get yourself a cup of tea. - Open the file
spine-cocos2dx\example\cocos2d\cocos\2d\cocos2dx.propsand remove thelibSpine.libentry from the<AdditionalDependencies>tag. - Open the
spine-runtimes/spine-cocos2dx/example/proj.win32/spine-cocos2d-x.slnfile in Visual Studio 2015. Visual Studio may ask you to install the Windows XP/7 SDK, which you should install. - Expand
Referencesof the libcocos2d sub project, and remove the entry forlibSpine, which should be marked with an error. - Right click the
spine-cocos2d-xproject in the solution explorer and selectSet as Startup Projectfrom the context menu - Click
Local Windows Debuggerto run the example
macOS/iOS
- Install Xcode
- Install Homebrew
- Open a terminal and install CMake via
brew install cmake - Download the Spine Runtimes repository using git (
git clone https://github.com/esotericsoftware/spine-runtimes) or download it as a zip via the download button above. - Open a terminal, and
cdinto thespine-runtimes/spine-cocos2dxfolder - Type
mkdir build && cd build && cmake ../... This will download the cocos2d-x dependency and wire it up with the example source code inspine-runtimes/spine-cocos2dx/example. The download is 400mb, so get yourself a cup of tea. - Open the Xcode project in
spine-runtimes/spine-cocos2dx/example/proj.ios_mac - Expand the
cocos2d_libs.xcodeprojsub project, delete the groupeditor-support/spine. This will remove the outdated Spine cocos2d-x runtime shipped by cocos2d-x. - Click the
Runbutton or typeCMD+Rto run the example
Android
- Install the prerequisits for cocos2d-x Android development
- Install Homebrew
- Open a terminal and install CMake via
brew install cmake - Download the Spine Runtimes repository using git (
git clone https://github.com/esotericsoftware/spine-runtimes) or download it as a zip via the download button above. - Open a terminal, and
cdinto thespine-runtimes/spine-cocos2dxfolder - Type
mkdir build && cd build && cmake ../... This will download the cocos2d-x dependency and wire it up with the example source code inspine-runtimes/spine-cocos2dx/example. The download is 400mb, so get yourself a cup of tea. - Delete
spine-runtimes/spine-cocos2dx/example/cocos2d/cocos/editor-support/spine - Open
spine-runtimes/spine-cocos2dx/example/cocos2d/cocos/Android.mkand remove the linesLOCAL_STATIC_LIBRARIES += spine_staticand `$(call import-module,editor-support/spine) - Switch to
spine-runtimes/spine-cocos2dx/example/proj.android/jniand executecocos compile -p android -m debug --ndk-mode debugto compile the example for Android - In the same directory, execute
cocos run -p android -m debugto deploy to the device - For debugging, run
ndk-debugin theproj.android/jnifolder. This will attach to the running app via GDB.
Notes
- Images are premultiplied by cocos2d-x, so the Spine atlas images should not use premultiplied alpha.
- Two color tinting needs to be enabled on a per-skeleton basis. Call
SkeletonRenderer::setTwoColorTine(true)orSkeletonAnimation::setTwoColorTint(true)after you created the skeleton instance. Note that two color tinting requires a custom shader and vertex format. Skeletons rendered with two color tinting can therefore not be batched with single color tinted skeletons or other 2D cocos2d-x elements like sprites. However, two-color tinted skeletons will be batched if possible when rendered after one another. Attaching a child to a two color tinted skeleton will also break the batch.