2010-08-16 10:02:06 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 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.
|
|
|
|
****************************************************************************/
|
2010-12-22 15:15:04 +08:00
|
|
|
#include "CCActionProgressTimer.h"
|
2010-08-21 10:26:26 +08:00
|
|
|
#include "CCProgressTimer.h"
|
2010-08-16 10:02:06 +08:00
|
|
|
|
|
|
|
namespace cocos2d
|
|
|
|
{
|
|
|
|
#define kProgressTimerCast CCProgressTimer*
|
|
|
|
|
|
|
|
// implementation of CCProgressTo
|
|
|
|
|
|
|
|
CCProgressTo* CCProgressTo::actionWithDuration(cocos2d::ccTime duration, float fPercent)
|
|
|
|
{
|
|
|
|
CCProgressTo *pProgressTo = new CCProgressTo();
|
|
|
|
pProgressTo->initWithDuration(duration, fPercent);
|
|
|
|
pProgressTo->autorelease();
|
|
|
|
|
|
|
|
return pProgressTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCProgressTo::initWithDuration(cocos2d::ccTime duration, float fPercent)
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
2010-08-16 10:02:06 +08:00
|
|
|
{
|
|
|
|
m_fTo = fPercent;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCObject* CCProgressTo::copyWithZone(cocos2d::CCZone *pZone)
|
2010-08-16 10:02:06 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCZone* pNewZone = NULL;
|
2010-08-16 10:02:06 +08:00
|
|
|
CCProgressTo* pCopy = NULL;
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
{
|
|
|
|
//in case of being called at sub class
|
2010-08-30 15:06:08 +08:00
|
|
|
pCopy = (CCProgressTo*)(pZone->m_pCopyObject);
|
2010-08-16 10:02:06 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pCopy = new CCProgressTo();
|
2011-03-07 17:11:57 +08:00
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
2010-08-16 10:02:06 +08:00
|
|
|
}
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInterval::copyWithZone(pZone);
|
2010-08-16 10:02:06 +08:00
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_fTo);
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-16 10:02:06 +08:00
|
|
|
return pCopy;
|
|
|
|
}
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
void CCProgressTo::startWithTarget(CCNode *pTarget)
|
2010-08-16 10:02:06 +08:00
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2010-08-30 15:06:08 +08:00
|
|
|
m_fFrom = ((kProgressTimerCast)(pTarget))->getPercentage();
|
2010-08-16 10:02:06 +08:00
|
|
|
|
|
|
|
// XXX: Is this correct ?
|
|
|
|
// Adding it to support CCRepeat
|
|
|
|
if (m_fFrom == 100)
|
|
|
|
{
|
|
|
|
m_fFrom = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCProgressTo::update(cocos2d::ccTime time)
|
|
|
|
{
|
2010-08-30 15:06:08 +08:00
|
|
|
((kProgressTimerCast)(m_pTarget))->setPercentage(m_fFrom + (m_fTo - m_fFrom) * time);
|
2010-08-16 10:02:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of CCProgressFromTo
|
|
|
|
|
|
|
|
CCProgressFromTo* CCProgressFromTo::actionWithDuration(cocos2d::ccTime duration, float fFromPercentage, float fToPercentage)
|
|
|
|
{
|
|
|
|
CCProgressFromTo *pProgressFromTo = new CCProgressFromTo();
|
|
|
|
pProgressFromTo->initWithDuration(duration, fFromPercentage, fToPercentage);
|
|
|
|
pProgressFromTo->autorelease();
|
|
|
|
|
|
|
|
return pProgressFromTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCProgressFromTo::initWithDuration(cocos2d::ccTime duration, float fFromPercentage, float fToPercentage)
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
2010-08-16 10:02:06 +08:00
|
|
|
{
|
|
|
|
m_fTo = fToPercentage;
|
|
|
|
m_fFrom = fFromPercentage;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCObject* CCProgressFromTo::copyWithZone(cocos2d::CCZone *pZone)
|
2010-08-16 10:02:06 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCZone* pNewZone = NULL;
|
2010-08-16 10:02:06 +08:00
|
|
|
CCProgressFromTo* pCopy = NULL;
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
{
|
|
|
|
//in case of being called at sub class
|
2010-08-30 15:06:08 +08:00
|
|
|
pCopy = (CCProgressFromTo*)(pZone->m_pCopyObject);
|
2010-08-16 10:02:06 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pCopy = new CCProgressFromTo();
|
2011-03-07 17:11:57 +08:00
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
2010-08-16 10:02:06 +08:00
|
|
|
}
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInterval::copyWithZone(pZone);
|
2010-08-16 10:02:06 +08:00
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_fFrom, m_fTo);
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-16 10:02:06 +08:00
|
|
|
return pCopy;
|
|
|
|
}
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInterval* CCProgressFromTo::reverse(void)
|
2010-08-16 10:02:06 +08:00
|
|
|
{
|
|
|
|
return CCProgressFromTo::actionWithDuration(m_fDuration, m_fTo, m_fFrom);
|
|
|
|
}
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
void CCProgressFromTo::startWithTarget(CCNode *pTarget)
|
2010-08-16 10:02:06 +08:00
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2010-08-16 10:02:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCProgressFromTo::update(cocos2d::ccTime time)
|
|
|
|
{
|
2010-08-30 15:06:08 +08:00
|
|
|
((kProgressTimerCast)(m_pTarget))->setPercentage(m_fFrom + (m_fTo - m_fFrom) * time);
|
2010-08-16 10:02:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}// end of namespace cocos2d
|