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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CCProcessBase.h"
|
|
|
|
#include "../utils/CCUtilMath.h"
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
NS_CC_EXT_ARMATURE_BEGIN
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
ProcessBase::ProcessBase(void)
|
2013-09-13 18:07:37 +08:00
|
|
|
: m_fProcessScale(1)
|
|
|
|
, m_bIsPause(true)
|
|
|
|
, m_bIsComplete(true)
|
|
|
|
, m_bIsPlaying(false)
|
|
|
|
, m_fCurrentPercent(0.0f)
|
|
|
|
, m_iRawDuration(0)
|
|
|
|
, m_eLoopType(ANIMATION_LOOP_BACK)
|
|
|
|
, m_eTweenEasing(Linear)
|
|
|
|
, m_iDurationTween(0)
|
|
|
|
, m_fCurrentFrame(0)
|
|
|
|
, m_iCurFrameIndex(0)
|
|
|
|
, m_bIsLoopBack(false)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
/*
|
2013-09-13 18:07:37 +08:00
|
|
|
* set m_fAnimationInternal defualt value to CCDirector::sharedDirector()
|
2013-06-06 12:02:54 +08:00
|
|
|
* ->getAnimationInterval(), in line with game update speed
|
|
|
|
*/
|
2013-09-14 19:54:49 +08:00
|
|
|
m_fAnimationInternal = CCDirector::getInstance()->getAnimationInterval();
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
ProcessBase::~ProcessBase(void)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ProcessBase::pause()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
m_bIsPause = true;
|
|
|
|
m_bIsPlaying = false;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ProcessBase::resume()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
m_bIsPause = false;
|
|
|
|
m_bIsPlaying = true;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ProcessBase::stop()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
m_bIsComplete = true;
|
|
|
|
m_bIsPlaying = false;
|
|
|
|
m_fCurrentFrame = 0;
|
|
|
|
m_fCurrentPercent = 0;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void ProcessBase::play(void *animation, int durationTo, int durationTween, int loop, int tweenEasing)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
m_bIsComplete = false;
|
|
|
|
m_bIsPause = false;
|
|
|
|
m_bIsPlaying = true;
|
|
|
|
m_fCurrentFrame = 0;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
/*
|
2013-09-13 18:07:37 +08:00
|
|
|
* Set m_iTotalFrames to durationTo, it is used for change tween between two animation.
|
|
|
|
* When changing end, m_iTotalFrames will be setted to _durationTween
|
2013-06-06 12:02:54 +08:00
|
|
|
*/
|
2013-09-13 18:07:37 +08:00
|
|
|
m_iNextFrameIndex = durationTo;
|
|
|
|
m_eTweenEasing = (CCTweenType)tweenEasing;
|
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 ProcessBase::update(float dt)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
if (m_bIsComplete || m_bIsPause)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
/*
|
2013-09-13 18:07:37 +08:00
|
|
|
* Fileter the m_iDuration <=0 and dt >1
|
2013-06-06 12:02:54 +08:00
|
|
|
* If dt>1, generally speaking the reason is the device is stuck.
|
|
|
|
*/
|
2013-09-13 18:07:37 +08:00
|
|
|
if(m_iRawDuration <= 0 || dt > 1)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
if (m_iNextFrameIndex <= 0)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
m_fCurrentPercent = 1;
|
|
|
|
m_fCurrentFrame = 0;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* update m_fCurrentFrame, every update add the frame passed.
|
|
|
|
* dt/m_fAnimationInternal determine it is not a frame animation. If frame speed changed, it will not make our
|
|
|
|
* animation speed slower or quicker.
|
|
|
|
*/
|
|
|
|
m_fCurrentFrame += m_fProcessScale * (dt / m_fAnimationInternal);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
m_fCurrentPercent = m_fCurrentFrame / m_iNextFrameIndex;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
/*
|
|
|
|
* if m_fCurrentFrame is bigger or equal than m_iTotalFrames, then reduce it util m_fCurrentFrame is
|
|
|
|
* smaller than m_iTotalFrames
|
|
|
|
*/
|
|
|
|
m_fCurrentFrame = fmodf(m_fCurrentFrame, m_iNextFrameIndex);
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
updateHandler();
|
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 ProcessBase::gotoFrame(int frameIndex)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
m_iCurFrameIndex = frameIndex;
|
|
|
|
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
|
|
|
int ProcessBase::getCurrentFrameIndex()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
m_iCurFrameIndex = m_iRawDuration * m_fCurrentPercent;
|
|
|
|
return m_iCurFrameIndex;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
NS_CC_EXT_ARMATURE_END
|