diff --git a/spine-cocos2dx/example/Classes/AppDelegate.cpp b/spine-cocos2dx/example/Classes/AppDelegate.cpp index adf74c682..3775a9893 100644 --- a/spine-cocos2dx/example/Classes/AppDelegate.cpp +++ b/spine-cocos2dx/example/Classes/AppDelegate.cpp @@ -36,6 +36,7 @@ #include "BatchingExample.h" #include "CoinExample.h" #include "SkeletonRendererSeparatorExample.h" +#include "MixAndMatchExample.h" #include #include "AppMacros.h" #include @@ -111,7 +112,7 @@ bool AppDelegate::applicationDidFinishLaunching () { // create a scene. it's an autorelease object //auto scene = RaptorExample::scene(); - auto scene = CoinExample::scene(); + auto scene = MixAndMatchExample::scene(); // run director->runWithScene(scene); diff --git a/spine-cocos2dx/example/Classes/CoinExample.cpp b/spine-cocos2dx/example/Classes/CoinExample.cpp index b37cdb405..85154299d 100644 --- a/spine-cocos2dx/example/Classes/CoinExample.cpp +++ b/spine-cocos2dx/example/Classes/CoinExample.cpp @@ -28,7 +28,7 @@ *****************************************************************************/ #include "CoinExample.h" -#include "BatchingExample.h" +#include "MixAndMatchExample.h" USING_NS_CC; using namespace spine; @@ -57,7 +57,7 @@ bool CoinExample::init () { else if (skeletonNode->getTimeScale() == 1) skeletonNode->setTimeScale(0.3f); else - Director::getInstance()->replaceScene(BatchingExample::scene()); + Director::getInstance()->replaceScene(MixAndMatchExample::scene()); return true; }; _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); diff --git a/spine-cocos2dx/example/Classes/MixAndMatchExample.cpp b/spine-cocos2dx/example/Classes/MixAndMatchExample.cpp new file mode 100644 index 000000000..6d8cad387 --- /dev/null +++ b/spine-cocos2dx/example/Classes/MixAndMatchExample.cpp @@ -0,0 +1,87 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated May 1, 2019. Replaces all prior versions. + * + * Copyright (c) 2013-2019, Esoteric Software LLC + * + * Integration of the Spine Runtimes into software or otherwise creating + * derivative works of the Spine Runtimes is permitted under the terms and + * conditions of Section 2 of the Spine Editor License Agreement: + * http://esotericsoftware.com/spine-editor-license + * + * Otherwise, it is permitted to integrate the Spine Runtimes into software + * or otherwise create derivative works of the Spine Runtimes (collectively, + * "Products"), provided that each user of the Products must obtain their own + * Spine Editor license and redistribution of the Products in any form must + * include this license and copyright notice. + * + * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN + * NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS + * INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +#include "MixAndMatchExample.h" +#include "BatchingExample.h" + +USING_NS_CC; +using namespace spine; + +Scene* MixAndMatchExample::scene () { + Scene *scene = Scene::create(); + scene->addChild(MixAndMatchExample::create()); + return scene; +} + +MixAndMatchExample::~MixAndMatchExample() { + delete skin; +} + +bool MixAndMatchExample::init () { + if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false; + + skeletonNode = SkeletonAnimation::createWithBinaryFile("mix-and-match-pro.skel", "mix-and-match.atlas", 0.5); + skeletonNode->setAnimation(0, "dance", true); + + // Create a new skin, by mixing and matching other skins + // that fit together. Items making up the girl are individual + // skins. Using the skin API, a new skin is created which is + // a combination of all these individual item skins. + SkeletonData* skeletonData = skeletonNode->getSkeleton()->getData(); + skin = new (__FILE__, __LINE__) Skin("mix-and-match"); + skin->addSkin(skeletonData->findSkin("skin-base")); + skin->addSkin(skeletonData->findSkin("nose/short")); + skin->addSkin(skeletonData->findSkin("eyes/eyelids-girly")); + skin->addSkin(skeletonData->findSkin("eyes/violet")); + skin->addSkin(skeletonData->findSkin("hair/brown")); + skin->addSkin(skeletonData->findSkin("clothes/hoodie-orange")); + skin->addSkin(skeletonData->findSkin("legs/pants-jeans")); + skin->addSkin(skeletonData->findSkin("accessories/bag")); + skin->addSkin(skeletonData->findSkin("accessories/hat-red-yellow")); + skeletonNode->getSkeleton()->setSkin(skin); + + skeletonNode->setPosition(Vec2(_contentSize.width / 2, _contentSize.height / 2 - 200)); + addChild(skeletonNode); + + scheduleUpdate(); + + EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create(); + listener->onTouchBegan = [this] (Touch* touch, cocos2d::Event* event) -> bool { + if (!skeletonNode->getDebugBonesEnabled()) + skeletonNode->setDebugBonesEnabled(true); + else if (skeletonNode->getTimeScale() == 1) + skeletonNode->setTimeScale(0.3f); + else + Director::getInstance()->replaceScene(BatchingExample::scene()); + return true; + }; + _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); + + return true; +} diff --git a/spine-cocos2dx/example/Classes/MixAndMatchExample.h b/spine-cocos2dx/example/Classes/MixAndMatchExample.h new file mode 100644 index 000000000..6b9f96fa9 --- /dev/null +++ b/spine-cocos2dx/example/Classes/MixAndMatchExample.h @@ -0,0 +1,51 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated May 1, 2019. Replaces all prior versions. + * + * Copyright (c) 2013-2019, Esoteric Software LLC + * + * Integration of the Spine Runtimes into software or otherwise creating + * derivative works of the Spine Runtimes is permitted under the terms and + * conditions of Section 2 of the Spine Editor License Agreement: + * http://esotericsoftware.com/spine-editor-license + * + * Otherwise, it is permitted to integrate the Spine Runtimes into software + * or otherwise create derivative works of the Spine Runtimes (collectively, + * "Products"), provided that each user of the Products must obtain their own + * Spine Editor license and redistribution of the Products in any form must + * include this license and copyright notice. + * + * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN + * NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS + * INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +#ifndef _MIXANDMATCHEXAMPLE_H_ +#define _MIXANDMATCHEXAMPLE_H_ + +#include "cocos2d.h" +#include + +class MixAndMatchExample : public cocos2d::LayerColor { +public: + static cocos2d::Scene* scene (); + + CREATE_FUNC(MixAndMatchExample); + + virtual bool init (); + + virtual ~MixAndMatchExample(); + +private: + spine::SkeletonAnimation* skeletonNode; + spine::Skin* skin; +}; + +#endif // _MIXANDMATCHXAMPLE_H_ diff --git a/spine-cocos2dx/example/proj.ios_mac/spine-cocos2d-x.xcodeproj/project.pbxproj b/spine-cocos2dx/example/proj.ios_mac/spine-cocos2d-x.xcodeproj/project.pbxproj index 1d3c32538..f0e9032a3 100644 --- a/spine-cocos2dx/example/proj.ios_mac/spine-cocos2d-x.xcodeproj/project.pbxproj +++ b/spine-cocos2dx/example/proj.ios_mac/spine-cocos2d-x.xcodeproj/project.pbxproj @@ -168,6 +168,8 @@ 763105DA20BC1B9700927A1E /* VertexEffect.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 763104AE20BC1B5800927A1E /* VertexEffect.cpp */; }; 76798D1D22A95AB400F77964 /* ConstraintData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76798D1C22A95AB300F77964 /* ConstraintData.cpp */; }; 76798D1E22A95AEF00F77964 /* ConstraintData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76798D1C22A95AB300F77964 /* ConstraintData.cpp */; }; + 767D80E322B29F22000BD703 /* MixAndMatchExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 767D80E022B29F22000BD703 /* MixAndMatchExample.cpp */; }; + 767D80E422B2A003000BD703 /* MixAndMatchExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 767D80E022B29F22000BD703 /* MixAndMatchExample.cpp */; }; 76A45BDE1E64396800745AA1 /* SkeletonTwoColorBatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76A45BDC1E64396800745AA1 /* SkeletonTwoColorBatch.cpp */; }; 76A45BDF1E64396800745AA1 /* SkeletonTwoColorBatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76A45BDC1E64396800745AA1 /* SkeletonTwoColorBatch.cpp */; }; 76AAA3C01D180F7C00C54FCB /* AppDelegate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3B31D180F7C00C54FCB /* AppDelegate.cpp */; }; @@ -364,6 +366,8 @@ 763104C120BC1B5E00927A1E /* ShearTimeline.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ShearTimeline.cpp; path = "../../../spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp"; sourceTree = ""; }; 763104C220BC1B5E00927A1E /* TranslateTimeline.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TranslateTimeline.cpp; path = "../../../spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp"; sourceTree = ""; }; 76798D1C22A95AB300F77964 /* ConstraintData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ConstraintData.cpp; path = "../../../spine-cpp/spine-cpp/src/spine/ConstraintData.cpp"; sourceTree = ""; }; + 767D80E022B29F22000BD703 /* MixAndMatchExample.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MixAndMatchExample.cpp; sourceTree = ""; }; + 767D80E222B29F22000BD703 /* MixAndMatchExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MixAndMatchExample.h; sourceTree = ""; }; 76A45BDC1E64396800745AA1 /* SkeletonTwoColorBatch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkeletonTwoColorBatch.cpp; path = ../../src/spine/SkeletonTwoColorBatch.cpp; sourceTree = ""; }; 76A45BDD1E64396800745AA1 /* SkeletonTwoColorBatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkeletonTwoColorBatch.h; path = ../../src/spine/SkeletonTwoColorBatch.h; sourceTree = ""; }; 76AAA3B31D180F7C00C54FCB /* AppDelegate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AppDelegate.cpp; sourceTree = ""; }; @@ -539,6 +543,8 @@ 46880B8319C43A87006E1F66 /* Classes */ = { isa = PBXGroup; children = ( + 767D80E022B29F22000BD703 /* MixAndMatchExample.cpp */, + 767D80E222B29F22000BD703 /* MixAndMatchExample.h */, 76D1BFDF2029E35200A0272D /* SkeletonRendererSeparatorExample.cpp */, 76D1BFDE2029E35100A0272D /* SkeletonRendererSeparatorExample.h */, 76D520E41EB362DD00572471 /* CoinExample.cpp */, @@ -871,6 +877,7 @@ 503AE10017EB989F00D1A890 /* AppController.mm in Sources */, 763104E820BC1B5E00927A1E /* BoundingBoxAttachment.cpp in Sources */, 763104C720BC1B5E00927A1E /* DrawOrderTimeline.cpp in Sources */, + 767D80E322B29F22000BD703 /* MixAndMatchExample.cpp in Sources */, 763104F520BC1B5E00927A1E /* MeshAttachment.cpp in Sources */, 763104E520BC1B5E00927A1E /* TwoColorTimeline.cpp in Sources */, 763104D420BC1B5E00927A1E /* IkConstraint.cpp in Sources */, @@ -920,6 +927,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 767D80E422B2A003000BD703 /* MixAndMatchExample.cpp in Sources */, 76798D1E22A95AEF00F77964 /* ConstraintData.cpp in Sources */, 7631059E20BC1B9700927A1E /* Animation.cpp in Sources */, 7631059F20BC1B9700927A1E /* AnimationState.cpp in Sources */,