diff --git a/spine-cocos2dx/example/Classes/GoblinsExample.cpp b/spine-cocos2dx/example/Classes/GoblinsExample.cpp index fe6841dfe..b2332d8e0 100644 --- a/spine-cocos2dx/example/Classes/GoblinsExample.cpp +++ b/spine-cocos2dx/example/Classes/GoblinsExample.cpp @@ -44,7 +44,7 @@ Scene* GoblinsExample::scene () { bool GoblinsExample::init () { if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false; - skeletonNode = SkeletonAnimation::createWithFile("goblins-mesh.json", "goblins.atlas", 1.5f); + skeletonNode = SkeletonAnimation::createWithJsonFile("goblins-mesh.json", "goblins.atlas", 1.5f); skeletonNode->setAnimation(0, "walk", true); skeletonNode->setSkin("goblin"); diff --git a/spine-cocos2dx/example/Classes/RaptorExample.cpp b/spine-cocos2dx/example/Classes/RaptorExample.cpp index 7a62bad09..6eb57c964 100644 --- a/spine-cocos2dx/example/Classes/RaptorExample.cpp +++ b/spine-cocos2dx/example/Classes/RaptorExample.cpp @@ -44,7 +44,7 @@ Scene* RaptorExample::scene () { bool RaptorExample::init () { if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false; - skeletonNode = SkeletonAnimation::createWithFile("raptor.json", "raptor.atlas", 0.5f); + skeletonNode = SkeletonAnimation::createWithJsonFile("raptor.json", "raptor.atlas", 0.5f); skeletonNode->setAnimation(0, "walk", true); skeletonNode->setAnimation(1, "empty", false); skeletonNode->addAnimation(1, "gungrab", false, 2); diff --git a/spine-cocos2dx/example/Classes/SpineboyExample.cpp b/spine-cocos2dx/example/Classes/SpineboyExample.cpp index fdeec2a29..a89ff5497 100644 --- a/spine-cocos2dx/example/Classes/SpineboyExample.cpp +++ b/spine-cocos2dx/example/Classes/SpineboyExample.cpp @@ -44,7 +44,7 @@ Scene* SpineboyExample::scene () { bool SpineboyExample::init () { if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false; - skeletonNode = SkeletonAnimation::createWithFile("spineboy.json", "spineboy.atlas", 0.6f); + skeletonNode = SkeletonAnimation::createWithJsonFile("spineboy.json", "spineboy.atlas", 0.6f); skeletonNode->setStartListener( [this] (int trackIndex) { spTrackEntry* entry = spAnimationState_getCurrent(skeletonNode->getState(), trackIndex); diff --git a/spine-cocos2dx/example/Classes/TankExample.cpp b/spine-cocos2dx/example/Classes/TankExample.cpp index d1f318d74..059ca56a1 100644 --- a/spine-cocos2dx/example/Classes/TankExample.cpp +++ b/spine-cocos2dx/example/Classes/TankExample.cpp @@ -44,7 +44,7 @@ Scene* TankExample::scene () { bool TankExample::init () { if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false; - skeletonNode = SkeletonAnimation::createWithFile("tank.json", "tank.atlas", 0.5f); + skeletonNode = SkeletonAnimation::createWithJsonFile("tank.json", "tank.atlas", 0.5f); skeletonNode->setAnimation(0, "drive", true); skeletonNode->setPosition(Vec2(_contentSize.width / 2 + 400, 20)); diff --git a/spine-cocos2dx/src/spine/SkeletonAnimation.cpp b/spine-cocos2dx/src/spine/SkeletonAnimation.cpp index f2037b16a..d26969aa5 100644 --- a/spine-cocos2dx/src/spine/SkeletonAnimation.cpp +++ b/spine-cocos2dx/src/spine/SkeletonAnimation.cpp @@ -80,7 +80,7 @@ SkeletonAnimation* SkeletonAnimation::createWithData (spSkeletonData* skeletonDa SkeletonAnimation* SkeletonAnimation::createWithJsonFile (const std::string& skeletonJsonFile, spAtlas* atlas, float scale) { SkeletonAnimation* node = new SkeletonAnimation(); - node->initWithJsonFile(skeletonJsonFile, atlas, scale); + node->initWithFile(skeletonJsonFile, atlas, scale); node->autorelease(); return node; } @@ -88,14 +88,14 @@ SkeletonAnimation* SkeletonAnimation::createWithJsonFile (const std::string& ske SkeletonAnimation* SkeletonAnimation::createWithJsonFile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale) { SkeletonAnimation* node = new SkeletonAnimation(); spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0); - node->initWithJsonFile(skeletonJsonFile, atlas, scale); + node->initWithFile(skeletonJsonFile, atlas, scale); node->autorelease(); return node; } SkeletonAnimation* SkeletonAnimation::createWithBinaryFile (const std::string& skeletonBinaryFile, spAtlas* atlas, float scale) { SkeletonAnimation* node = new SkeletonAnimation(); - node->initWithBinaryFile(skeletonBinaryFile, atlas, scale); + node->initWithFile(skeletonBinaryFile, atlas, scale); node->autorelease(); return node; } @@ -103,7 +103,7 @@ SkeletonAnimation* SkeletonAnimation::createWithBinaryFile (const std::string& s SkeletonAnimation* SkeletonAnimation::createWithBinaryFile (const std::string& skeletonBinaryFile, const std::string& atlasFile, float scale) { SkeletonAnimation* node = new SkeletonAnimation(); spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0); - node->initWithBinaryFile(skeletonBinaryFile, atlas, scale); + node->initWithFile(skeletonBinaryFile, atlas, scale); node->autorelease(); return node; } @@ -142,8 +142,8 @@ void SkeletonAnimation::update (float deltaTime) { void SkeletonAnimation::setAnimationStateData (spAnimationStateData* stateData) { CCASSERT(stateData, "stateData cannot be null."); - if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data); - spAnimationState_dispose(_state); + if (_ownsAnimationStateData) spAnimationStateData_dispose(_state->data); + spAnimationState_dispose(_state); _ownsAnimationStateData = false; _state = spAnimationState_create(stateData); diff --git a/spine-cocos2dx/src/spine/SkeletonBatch.cpp b/spine-cocos2dx/src/spine/SkeletonBatch.cpp index fc78b8ffb..974dc15e0 100644 --- a/spine-cocos2dx/src/spine/SkeletonBatch.cpp +++ b/spine-cocos2dx/src/spine/SkeletonBatch.cpp @@ -81,15 +81,21 @@ namespace spine { void SkeletonBatch::addCommand (cocos2d::Renderer* renderer, float globalZOrder, GLuint textureID, GLProgramState* glProgramState, BlendFunc blendFunc, const TrianglesCommand::Triangles& triangles, const Mat4& transform, uint32_t transformFlags ) { - _command->triangles->verts = triangles.verts; - + if (_command->triangles->verts) { + free(_command->triangles->verts); + _command->triangles->verts = NULL; + } + + _command->triangles->verts = (V3F_C4B_T2F *)malloc(sizeof(V3F_C4B_T2F) * triangles.vertCount); + memcpy(_command->triangles->verts, triangles.verts, sizeof(V3F_C4B_T2F) * triangles.vertCount); + _command->triangles->vertCount = triangles.vertCount; _command->triangles->indexCount = triangles.indexCount; _command->triangles->indices = triangles.indices; - + _command->trianglesCommand->init(globalZOrder, textureID, glProgramState, blendFunc, *_command->triangles, transform); renderer->addCommand(_command->trianglesCommand); - + if (!_command->next) _command->next = new Command(); _command = _command->next; } @@ -102,6 +108,9 @@ namespace spine { } SkeletonBatch::Command::~Command () { + if (triangles->verts) { + free(triangles->verts); + } delete triangles; delete trianglesCommand; } diff --git a/spine-cocos2dx/src/spine/SkeletonRenderer.h b/spine-cocos2dx/src/spine/SkeletonRenderer.h index 50cbed388..053a9dbff 100644 --- a/spine-cocos2dx/src/spine/SkeletonRenderer.h +++ b/spine-cocos2dx/src/spine/SkeletonRenderer.h @@ -111,7 +111,7 @@ CC_CONSTRUCTOR_ACCESS: void initWithFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1); void initWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1); - void initialize (); + virtual void initialize (); protected: void setSkeletonData (spSkeletonData* skeletonData, bool ownsSkeletonData);