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-c.
Licensing
This Spine Runtime may only be used for personal or internal use, typically to evaluate Spine before purchasing. If you would like to incorporate a Spine Runtime into your applications, distribute software containing a Spine Runtime, or modify a Spine Runtime, then you will need a valid Spine license. Please see the Spine Runtimes Software License for detailed information.
The Spine Runtimes are developed with the intent to be used with data exported from Spine. By purchasing Spine, Section 2 of the Spine Software License grants the right to create and distribute derivative works of the Spine Runtimes.
Setup
- Download the Spine Runtimes source using git or by downloading it as a zip.
- Place the contents of a cocos2d-x version 3.x distribution into the
spine-cocos2dx/3/cocos2dxdirectory. - Run the
python download-deps.pyscript in thespine-cocos2dx/3/cocos2dxdirectory. - Open the XCode (Mac) or Visual C++ 2012 Express (Windows) project file from the
spine-cocos2dx/3/exampledirectory. Build files are also provided for Android.
Alternatively, the contents of the spine-c/src, spine-c/include and spine-cocos2dx/3/src directories can be copied into your project. Be sure your header search path will find the contents of the spine-c/include and spine-cocos2dx/3.1/src directories. Note that the includes use spine/Xxx.h, so the spine directory cannot be omitted when copying the files.
Setup for Cocos Studio Users (cocos2d-x-3.1)
- Download the Spine Runtimes source using git or by downloading it as a zip.
- Extract them somewhere you can find them. You will only need
spine-candspine-cocos2dx.
- Extract them somewhere you can find them. You will only need
- Download and install Cocos: http://www.cocos2d-x.org/download
- (2016 March 4) Downloading and installing Cocos Studio and cocos2d-x-3.1 includes a Spine runtime in their source files. For instance, if the default install folder is
C:\Cocos\, you will find an existing spine-c and spine-cocos2dx runtime insideC:\Cocos\Cocos2d-x\cocos2d-x-3.10\cocos\editor-support\spine.- Replace the contents of that folder with the files from the following Spine runtime folders:
spine-c/src/spinespine-c/include/spinespine-cocos2dx/3/src/spine
- Since this is the shared version of the runtime Cocos Studio uses for all projects created through it, updating the Spine runtime here also updates the Spine runtime of all those projects.
- Replace the contents of that folder with the files from the following Spine runtime folders:
- (2016 March 4) Downloading and installing Cocos Studio and cocos2d-x-3.1 includes a Spine runtime in their source files. For instance, if the default install folder is
Examples
- The
spine-cocos2dx/3/runtime folder contains a folder namedexample.- Copy the files in
spine-cocos2dx/3/example/Classesfolder (exceptAppDelegate.cpp,AppDelegate.handAppMacros.hinto theClassesfolder of your Cocos Studio project.)
- Copy the files in
- Add these files into your C++ Solution. (through your IDE, Visual Studio or Eclipse, etc...)
- If this is a newly created project, edit the
AppDelegate.cpp. For this example, we will use RaptorExample.- Add
#include "RaptorExample.h"to the includes near the top of the file. - Look for the
bool AppDelegate::applicationDidFinishLaunching()method and replace it with this. Notice the line where it defines the sceneauto scene = RaptorExample::scene():
- Add
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLViewImpl::createWithRect("Spine Test", Rect(0, 0, 960, 640));
director->setOpenGLView(glview);
}
director->getOpenGLView()->setDesignResolutionSize(960, 640, ResolutionPolicy::SHOW_ALL);
// turn on display FPS
director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0f / 60);
FileUtils::getInstance()->addSearchPath("res");
// create a scene. it's an autorelease object
auto scene = RaptorExample::scene();
// run
director->runWithScene(scene);
return true;
}
You can do the same with GoblinsExample and SpineboyExample.
Notes
- Images are premultiplied by cocos2d-x, so the Spine atlas images should not use premultiplied alpha.