2013-06-06 12:02:54 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-06-08 11:16:17 +08:00
|
|
|
#include "CCArmatureAnimation.h"
|
2013-06-06 12:02:54 +08:00
|
|
|
#include "../CCArmature.h"
|
|
|
|
#include "../CCBone.h"
|
|
|
|
#include "../utils/CCArmatureDefine.h"
|
|
|
|
#include "../utils/CCUtilMath.h"
|
|
|
|
#include "../datas/CCDatas.h"
|
|
|
|
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
NS_CC_EXT_ARMATURE_BEGIN
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
ArmatureAnimation *ArmatureAnimation::create(Armature *armature)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
ArmatureAnimation *pArmatureAnimation = new ArmatureAnimation();
|
2013-06-08 11:16:17 +08:00
|
|
|
if (pArmatureAnimation && pArmatureAnimation->init(armature))
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-08 11:16:17 +08:00
|
|
|
pArmatureAnimation->autorelease();
|
|
|
|
return pArmatureAnimation;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-08 11:16:17 +08:00
|
|
|
CC_SAFE_DELETE(pArmatureAnimation);
|
2013-06-06 12:02:54 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
ArmatureAnimation::ArmatureAnimation()
|
2013-09-15 20:24:25 +08:00
|
|
|
: _animationData(NULL)
|
|
|
|
, _speedScale(1)
|
|
|
|
, _movementData(NULL)
|
|
|
|
, _armature(NULL)
|
|
|
|
, _movementID("")
|
|
|
|
, _toIndex(0)
|
|
|
|
|
|
|
|
, _movementEventCallFunc(NULL)
|
|
|
|
, _frameEventCallFunc(NULL)
|
|
|
|
, _movementEventTarget(NULL)
|
|
|
|
, _frameEventTarget(NULL)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
ArmatureAnimation::~ArmatureAnimation(void)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(_tweenList);
|
|
|
|
CC_SAFE_RELEASE_NULL(_animationData);
|
2013-08-22 11:12:09 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(_movementEventTarget);
|
|
|
|
CC_SAFE_RELEASE_NULL(_frameEventTarget);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
bool ArmatureAnimation::init(Armature *armature)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
bool bRet = false;
|
|
|
|
do
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_armature = armature;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
_tweenList = new Array();
|
|
|
|
_tweenList->init();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
while (0);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ArmatureAnimation:: pause()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Object *object = NULL;
|
2013-09-15 20:24:25 +08:00
|
|
|
CCARRAY_FOREACH(_tweenList, object)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-16 14:13:55 +08:00
|
|
|
static_cast<Tween*>(object)->pause();
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-09-15 19:08:45 +08:00
|
|
|
ProcessBase::pause();
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ArmatureAnimation::resume()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Object *object = NULL;
|
2013-09-15 20:24:25 +08:00
|
|
|
CCARRAY_FOREACH(_tweenList, object)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-16 14:13:55 +08:00
|
|
|
static_cast<Tween*>(object)->resume();
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-09-15 19:08:45 +08:00
|
|
|
ProcessBase::resume();
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ArmatureAnimation::stop()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Object *object = NULL;
|
2013-09-15 20:24:25 +08:00
|
|
|
CCARRAY_FOREACH(_tweenList, object)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-16 14:13:55 +08:00
|
|
|
static_cast<Tween*>(object)->stop();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-09-15 20:24:25 +08:00
|
|
|
_tweenList->removeAllObjects();
|
2013-09-15 19:08:45 +08:00
|
|
|
ProcessBase::stop();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ArmatureAnimation::setAnimationScale(float animationScale )
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
|
|
|
setSpeedScale(animationScale);
|
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
float ArmatureAnimation::getAnimationScale() const
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
|
|
|
return getSpeedScale();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ArmatureAnimation::setSpeedScale(float speedScale)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
if(speedScale == _speedScale)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
_speedScale = speedScale;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
_processScale = !_movementData ? _speedScale : _speedScale * _movementData->scale;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
DictElement *element = NULL;
|
2013-09-15 20:24:25 +08:00
|
|
|
Dictionary *dict = _armature->getBoneDic();
|
2013-09-13 18:07:37 +08:00
|
|
|
CCDICT_FOREACH(dict, element)
|
|
|
|
{
|
2013-09-16 14:13:55 +08:00
|
|
|
Bone *bone = static_cast<Bone*>(element->getObject());
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
bone->getTween()->setProcessScale(_processScale);
|
2013-09-13 18:07:37 +08:00
|
|
|
if (bone->getChildArmature())
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
bone->getChildArmature()->getAnimation()->setProcessScale(_processScale);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
float ArmatureAnimation::getSpeedScale() const
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
return _speedScale;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ArmatureAnimation::setAnimationInternal(float animationInternal)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
if(animationInternal == _animationInternal)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
_animationInternal = animationInternal;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
DictElement *element = NULL;
|
2013-09-15 20:24:25 +08:00
|
|
|
Dictionary *dict = _armature->getBoneDic();
|
2013-06-07 10:52:32 +08:00
|
|
|
CCDICT_FOREACH(dict, element)
|
|
|
|
{
|
2013-09-16 14:13:55 +08:00
|
|
|
Bone *bone = static_cast<Bone*>(element->getObject());
|
2013-09-15 20:24:25 +08:00
|
|
|
bone->getTween()->setAnimationInternal(_animationInternal);
|
2013-06-07 10:52:32 +08:00
|
|
|
if (bone->getChildArmature())
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
bone->getChildArmature()->getAnimation()->setAnimationInternal(_animationInternal);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ArmatureAnimation::play(const char *animationName, int durationTo, int durationTween, int loop, int tweenEasing)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-16 12:02:57 +08:00
|
|
|
CCASSERT(_animationData, "_animationData can not be null");
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
_movementData = _animationData->getMovement(animationName);
|
2013-09-16 12:02:57 +08:00
|
|
|
CCASSERT(_movementData, "_movementData can not be null");
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
//! Get key frame count
|
2013-09-15 20:24:25 +08:00
|
|
|
_rawDuration = _movementData->duration;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
_movementID = animationName;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
_processScale = _speedScale * _movementData->scale;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
//! Further processing parameters
|
2013-09-15 20:24:25 +08:00
|
|
|
durationTo = (durationTo == -1) ? _movementData->durationTo : durationTo;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
durationTween = (durationTween == -1) ? _movementData->durationTween : durationTween;
|
|
|
|
durationTween = (durationTween == 0) ? _movementData->duration : durationTween;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
tweenEasing = (tweenEasing == TWEEN_EASING_MAX) ? _movementData->tweenEasing : tweenEasing;
|
|
|
|
loop = (loop < 0) ? _movementData->loop : loop;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
ProcessBase::play((void *)animationName, durationTo, durationTween, loop, tweenEasing);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
if (_rawDuration == 0)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_loopType = SINGLE_FRAME;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (loop)
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_loopType = ANIMATION_TO_LOOP_FRONT;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_loopType = ANIMATION_NO_LOOP;
|
|
|
|
_rawDuration --;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-09-15 20:24:25 +08:00
|
|
|
_durationTween = durationTween;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
MovementBoneData *movementBoneData = NULL;
|
2013-09-15 20:24:25 +08:00
|
|
|
_tweenList->removeAllObjects();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
DictElement *element = NULL;
|
2013-09-15 20:24:25 +08:00
|
|
|
Dictionary *dict = _armature->getBoneDic();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
CCDICT_FOREACH(dict, element)
|
|
|
|
{
|
2013-09-16 14:13:55 +08:00
|
|
|
Bone *bone = static_cast<Bone*>(element->getObject());
|
|
|
|
movementBoneData = static_cast<MovementBoneData *>(_movementData->movBoneDataDic.objectForKey(bone->getName()));
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
Tween *tween = bone->getTween();
|
2013-09-13 18:07:37 +08:00
|
|
|
if(movementBoneData && movementBoneData->frameList.count() > 0)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_tweenList->addObject(tween);
|
|
|
|
movementBoneData->duration = _movementData->duration;
|
2013-06-06 12:02:54 +08:00
|
|
|
tween->play(movementBoneData, durationTo, durationTween, loop, tweenEasing);
|
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
tween->setProcessScale(_processScale);
|
|
|
|
tween->setAnimationInternal(_animationInternal);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
if (bone->getChildArmature())
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
bone->getChildArmature()->getAnimation()->setProcessScale(_processScale);
|
|
|
|
bone->getChildArmature()->getAnimation()->setAnimationInternal(_animationInternal);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
if(!bone->getIgnoreMovementBoneData())
|
|
|
|
{
|
|
|
|
//! this bone is not include in this movement, so hide it
|
|
|
|
bone->getDisplayManager()->changeDisplayByIndex(-1, false);
|
|
|
|
tween->stop();
|
|
|
|
}
|
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ArmatureAnimation::playByIndex(int animationIndex, int durationTo, int durationTween, int loop, int tweenEasing)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
std::vector<std::string> &movName = _animationData->movementNames;
|
2013-06-07 17:10:53 +08:00
|
|
|
CC_ASSERT((animationIndex > -1) && ((unsigned int)animationIndex < movName.size()));
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
std::string animationName = movName.at(animationIndex);
|
|
|
|
play(animationName.c_str(), durationTo, durationTween, loop, tweenEasing);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
int ArmatureAnimation::getMovementCount()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
return _animationData->getMovementCount();
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ArmatureAnimation::update(float dt)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
ProcessBase::update(dt);
|
2013-06-20 14:15:53 +08:00
|
|
|
Object *object = NULL;
|
2013-09-15 20:24:25 +08:00
|
|
|
CCARRAY_FOREACH(_tweenList, object)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-16 14:13:55 +08:00
|
|
|
static_cast<Tween *>(object)->update(dt);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ArmatureAnimation::updateHandler()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
if (_currentPercent >= 1)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
switch(_loopType)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
case ANIMATION_NO_LOOP:
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_loopType = ANIMATION_MAX;
|
2013-09-16 14:13:55 +08:00
|
|
|
_currentFrame = (_currentPercent - 1) * _nextFrameIndex;
|
2013-09-15 20:24:25 +08:00
|
|
|
_currentPercent = _currentFrame / _durationTween;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
if (_currentPercent >= 1.0f)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-16 14:13:55 +08:00
|
|
|
_nextFrameIndex = _durationTween;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
if (_movementEventTarget && _movementEventCallFunc)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
(_movementEventTarget->*_movementEventCallFunc)(_armature, START, _movementID.c_str());
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ANIMATION_MAX:
|
|
|
|
case SINGLE_FRAME:
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_currentPercent = 1;
|
|
|
|
_isComplete = true;
|
|
|
|
_isPlaying = false;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
if (_movementEventTarget && _movementEventCallFunc)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
(_movementEventTarget->*_movementEventCallFunc)(_armature, COMPLETE, _movementID.c_str());
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ANIMATION_TO_LOOP_FRONT:
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_loopType = ANIMATION_LOOP_FRONT;
|
|
|
|
_currentPercent = fmodf(_currentPercent, 1);
|
2013-09-16 14:13:55 +08:00
|
|
|
_currentFrame = _nextFrameIndex == 0 ? 0 : fmodf(_currentFrame, _nextFrameIndex);
|
|
|
|
_nextFrameIndex = _durationTween > 0 ? _durationTween : 1;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
if (_movementEventTarget && _movementEventCallFunc)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
(_movementEventTarget->*_movementEventCallFunc)(_armature, START, _movementID.c_str());
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
//_currentPercent = fmodf(_currentPercent, 1);
|
2013-09-16 14:13:55 +08:00
|
|
|
_currentFrame = fmodf(_currentFrame, _nextFrameIndex);
|
2013-09-15 20:24:25 +08:00
|
|
|
_toIndex = 0;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
if (_movementEventTarget && _movementEventCallFunc)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
(_movementEventTarget->*_movementEventCallFunc)(_armature, LOOP_COMPLETE, _movementID.c_str());
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
std::string ArmatureAnimation::getCurrentMovementID()
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
if (_isComplete)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
return "";
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-09-15 20:24:25 +08:00
|
|
|
return _movementID;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ArmatureAnimation::setMovementEventCallFunc(Object *target, SEL_MovementEventCallFunc callFunc)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
if (target != _movementEventTarget)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
|
|
|
CC_SAFE_RETAIN(target);
|
2013-09-15 20:24:25 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(_movementEventTarget);
|
|
|
|
_movementEventTarget = target;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-09-15 20:24:25 +08:00
|
|
|
_movementEventCallFunc = callFunc;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ArmatureAnimation::setFrameEventCallFunc(Object *target, SEL_FrameEventCallFunc callFunc)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
if (target != _frameEventTarget)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
|
|
|
CC_SAFE_RETAIN(target);
|
2013-09-15 20:24:25 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(_frameEventTarget);
|
|
|
|
_frameEventTarget = target;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-09-15 20:24:25 +08:00
|
|
|
_frameEventCallFunc = callFunc;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ArmatureAnimation::frameEvent(Bone *bone, const char *frameEventName, int originFrameIndex, int currentFrameIndex)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
if (_frameEventTarget && _frameEventCallFunc)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
(_frameEventTarget->*_frameEventCallFunc)(bone, frameEventName, originFrameIndex, currentFrameIndex);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_CC_EXT_ARMATURE_END
|