// // spine的加载类 // #ifndef RUQCoreSpine_h #define RUQCoreSpine_h #include "cocos2d.h" #include "editor-support/spine/spine-cocos2dx.h" //#include "editor-support/spine/spine.h" #include "Redream.h" #include "RUDefine.h" USING_NS_CC; using namespace std; //using namespace spine; NS_RU_BEGIN class QCoreSpine :public spine::SkeletonAnimation { public: CREATE_FUNC(QCoreSpine); static spine::Atlas* getAtlasByName(std::string name); static spine::SkeletonData* getSkeletonDataByName(std::string name,spine::Atlas* atlas); static QCoreSpine* createWithData (spine::SkeletonData* skeletonData, bool ownsSkeletonData = false); static QCoreSpine* createWithJsonFile (const std::string& skeletonJsonFile, spine::Atlas* atlas, float scale = 1); static QCoreSpine* createWithJsonFile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale = 1); static QCoreSpine* createWithBinaryFile (const std::string& skeletonBinaryFile, spine::Atlas* atlas, float scale = 1); static QCoreSpine* createWithBinaryFile (const std::string& skeletonBinaryFile, const std::string& atlasFile, float scale = 1); //通过缓存创建spine节点 static QCoreSpine* createWithBinaryFileAndCache (const std::string& skeletonBinaryFile, const std::string& atlasFile, float scale = 1); void changeSkeleton(const std::string& skeletonJsonFile, const std::string& atlasFile, float scale = 1); virtual float getAnimTime(std::string name); virtual void playAnim(string name,const std::function &func = nullptr, bool isDeleteSelf = false ,bool isLoop = false,float delay = 0,bool delFunc = true); virtual void playAnimN(string name,const std::function &funcN = nullptr, bool isDeleteSelf = false ,bool isLoop = false); virtual void playRandomAnim(); virtual void playAnimInRangeWithArray(std::vector randomNames ,std::vector randomRates); // 倒序播放 virtual void playBackAnim(const char* name,const std::function &func = nullptr, bool isDeleteSelf = false ,bool isLoop = false); virtual void playAnimInRange(const char* name = "normal_"); QCoreSpine (); ~QCoreSpine(); virtual void onExit() override; //获取动画数据 spine::SkeletonData* getSkeletonData(); void setEventCallBack(const std::function &func); void changeToOtherParent(Node* newParent); std::function setCbOnExit(std::function cb); string getRunningSequenceName(); float getAnimDuration(std::string name); private: //重置变量 void resetVar(); void setContent(); private: void setDataName(const string& name); std::function _cbOnExit = nullptr; string _dataName; std::function _mComplete; std::function _mCallFunc; std::function _mCallFuncN; std::function _mCallEvent; std::vector _randomNames; std::vector _randomRates; static void reScaleSkeletonData(spine::SkeletonData* skeletonData,float scale); }; class QCoreSpineLoader : public redream::NodeLoader { public: RED_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(QCoreSpineLoader, loader); protected: RED_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(QCoreSpine); virtual void onHandlePropTypeString(cocos2d::Node * pNode, cocos2d::Node * pParent, const char* pPropertyName, const char * pString, redream::REDReader * ccbReader); virtual void onHandlePropTypeFloat(cocos2d::Node * pNode, cocos2d::Node * pParent, const char* pPropertyName, float pFloat, redream::REDReader * ccbReader); virtual void onHandlePropTypeCheck(cocos2d::Node * pNode, cocos2d::Node * pParent, const char* pPropertyName, bool pCheck, redream::REDReader * ccbReader); void checkRefreshSpine(cocos2d::Node * pNode); private: std::string _skelName = ""; std::string _atlasName = ""; std::string _curAnimName = ""; float _spineScale = 0.0f; bool _loop = false; }; NS_RU_END #endif /* defined(RUQCoreSpine_h) */