diff --git a/extensions/CocoStudio/Armature/animation/CCTween.cpp b/extensions/CocoStudio/Armature/animation/CCTween.cpp index 22893e3dd6..10a924721c 100644 --- a/extensions/CocoStudio/Armature/animation/CCTween.cpp +++ b/extensions/CocoStudio/Armature/animation/CCTween.cpp @@ -271,25 +271,25 @@ void Tween::updateHandler() } } -void Tween::setBetween(FrameData *from, FrameData *to) +void Tween::setBetween(FrameData *from, FrameData *to, bool limit) { do { if(from->displayIndex < 0 && to->displayIndex >= 0) { _from->copy(to); - _between->subtract(to, to); + _between->subtract(to, to, limit); break; } else if(to->displayIndex < 0 && from->displayIndex >= 0) { _from->copy(from); - _between->subtract(to, to); + _between->subtract(to, to, limit); break; } _from->copy(from); - _between->subtract(from, to); + _between->subtract(from, to, limit); } while (0); @@ -427,7 +427,7 @@ float Tween::updateFrameData(float currentPercent) _frameTweenEasing = from->tweenEasing; - setBetween(from, to); + setBetween(from, to, false); } currentPercent = _betweenDuration == 0 ? 0 : (playedTime - _totalDuration) / (float)_betweenDuration; diff --git a/extensions/CocoStudio/Armature/animation/CCTween.h b/extensions/CocoStudio/Armature/animation/CCTween.h index 6069ccb0fb..b4a64bc3ef 100644 --- a/extensions/CocoStudio/Armature/animation/CCTween.h +++ b/extensions/CocoStudio/Armature/animation/CCTween.h @@ -106,7 +106,7 @@ protected: /** * Calculate the between value of _from and _to, and give it to between frame data */ - virtual void setBetween(FrameData *from, FrameData *to); + virtual void setBetween(FrameData *from, FrameData *to, bool limit = true); /** * According to the percent to calculate current FrameData with tween effect diff --git a/extensions/CocoStudio/Armature/datas/CCDatas.cpp b/extensions/CocoStudio/Armature/datas/CCDatas.cpp index ce1839059e..bf6758dc04 100644 --- a/extensions/CocoStudio/Armature/datas/CCDatas.cpp +++ b/extensions/CocoStudio/Armature/datas/CCDatas.cpp @@ -74,7 +74,7 @@ void BaseData::copy(const BaseData *node ) } -void BaseData::subtract(BaseData *from, BaseData *to) +void BaseData::subtract(BaseData *from, BaseData *to, bool limit) { x = to->x - from->x; y = to->y - from->y; @@ -98,22 +98,25 @@ void BaseData::subtract(BaseData *from, BaseData *to) isUseColorInfo = false; } - if (skewX > M_PI) - { - skewX -= (float)CC_DOUBLE_PI; - } - if (skewX < -M_PI) - { - skewX += (float)CC_DOUBLE_PI; - } + if (limit) + { + if (skewX > M_PI) + { + skewX -= (float)CC_DOUBLE_PI; + } + if (skewX < -M_PI) + { + skewX += (float)CC_DOUBLE_PI; + } - if (skewY > M_PI) - { - skewY -= (float)CC_DOUBLE_PI; - } - if (skewY < -M_PI) - { - skewY += (float)CC_DOUBLE_PI; + if (skewY > M_PI) + { + skewY -= (float)CC_DOUBLE_PI; + } + if (skewY < -M_PI) + { + skewY += (float)CC_DOUBLE_PI; + } } if (to->tweenRotate) @@ -121,6 +124,7 @@ void BaseData::subtract(BaseData *from, BaseData *to) skewX += to->tweenRotate; skewY -= to->tweenRotate; } + } void BaseData::setColor(const Color4B &color) diff --git a/extensions/CocoStudio/Armature/datas/CCDatas.h b/extensions/CocoStudio/Armature/datas/CCDatas.h index 7b69e9c438..73e7df9097 100644 --- a/extensions/CocoStudio/Armature/datas/CCDatas.h +++ b/extensions/CocoStudio/Armature/datas/CCDatas.h @@ -87,7 +87,7 @@ public: * @param from from BaseData * @param to to BaseData */ - virtual void subtract(BaseData *from, BaseData *to); + virtual void subtract(BaseData *from, BaseData *to, bool limit); virtual void setColor(const Color4B &color); virtual Color4B getColor(); diff --git a/extensions/CocoStudio/Armature/utils/CCArmatureDefine.h b/extensions/CocoStudio/Armature/utils/CCArmatureDefine.h index 488bb0a1cc..fdf82a43c0 100644 --- a/extensions/CocoStudio/Armature/utils/CCArmatureDefine.h +++ b/extensions/CocoStudio/Armature/utils/CCArmatureDefine.h @@ -30,7 +30,7 @@ THE SOFTWARE. #include "ExtensionMacros.h" #define VERSION_COMBINED 0.30f - +#define VERSION_CHANGE_ROTATION_RANGE 1.0f #ifndef AUTO_ADD_SPRITE_FRAME_NAME_PREFIX #define AUTO_ADD_SPRITE_FRAME_NAME_PREFIX 0 diff --git a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp index a9c7830706..f2b756e018 100644 --- a/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp +++ b/extensions/CocoStudio/Armature/utils/CCDataReaderHelper.cpp @@ -853,6 +853,28 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *mov } + //! Change rotation range from (-180 -- 180) to (-infinity -- infinity) + CCFrameData **frames = (CCFrameData **)movBoneData->frameList.data->arr; + for (int i = movBoneData->frameList.count() - 1; i >= 0; i--) + { + if (i > 0) + { + float difSkewX = frames[i]->skewX - frames[i - 1]->skewX; + float difSkewY = frames[i]->skewY - frames[i - 1]->skewY; + + if (difSkewX < -M_PI || difSkewX > M_PI) + { + frames[i - 1]->skewX = difSkewX < 0 ? frames[i - 1]->skewX - 2 * M_PI : frames[i - 1]->skewX + 2 * M_PI; + } + + if (difSkewY < -M_PI || difSkewY > M_PI) + { + frames[i - 1]->skewY = difSkewY < 0 ? frames[i - 1]->skewY - 2 * M_PI : frames[i - 1]->skewY + 2 * M_PI; + } + } + } + + // FrameData *frameData = new FrameData(); frameData->copy((FrameData *)movBoneData->frameList.getLastObject()); @@ -1405,6 +1427,31 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(cs::JsonDictionary &json) delete dic; } + + if (s_CocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE) + { + //! Change rotation range from (-180 -- 180) to (-infinity -- infinity) + CCFrameData **frames = (CCFrameData **)movementBoneData->frameList.data->arr; + for (int i = movementBoneData->frameList.count() - 1; i >= 0; i--) + { + if (i > 0) + { + float difSkewX = frames[i]->skewX - frames[i - 1]->skewX; + float difSkewY = frames[i]->skewY - frames[i - 1]->skewY; + + if (difSkewX < -M_PI || difSkewX > M_PI) + { + frames[i - 1]->skewX = difSkewX < 0 ? frames[i - 1]->skewX - 2 * M_PI : frames[i - 1]->skewX + 2 * M_PI; + } + + if (difSkewY < -M_PI || difSkewY > M_PI) + { + frames[i - 1]->skewY = difSkewY < 0 ? frames[i - 1]->skewY - 2 * M_PI : frames[i - 1]->skewY + 2 * M_PI; + } + } + } + } + if (s_CocoStudioVersion < VERSION_COMBINED) { if (movementBoneData->frameList.count() > 0)