2010-08-06 10:51:40 +08:00
|
|
|
|
/****************************************************************************
|
2011-03-19 10:34:26 +08:00
|
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2011-07-01 15:08:23 +08:00
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2011-03-19 10:34:26 +08:00
|
|
|
|
|
2010-08-06 10:51:40 +08:00
|
|
|
|
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 "CCActionInterval.h"
|
2010-08-06 10:51:40 +08:00
|
|
|
|
#include "CCSprite.h"
|
|
|
|
|
#include "CCNode.h"
|
2011-03-07 17:11:57 +08:00
|
|
|
|
#include "CCPointExtension.h"
|
|
|
|
|
#include "CCStdC.h"
|
2010-08-06 10:51:40 +08:00
|
|
|
|
|
2010-08-25 14:14:31 +08:00
|
|
|
|
#include <stdarg.h>
|
2010-08-06 14:44:17 +08:00
|
|
|
|
|
2010-08-06 10:51:40 +08:00
|
|
|
|
namespace cocos2d {
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// IntervalAction
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCActionInterval::actionWithDuration(ccTime d)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval *pAction = new CCActionInterval();
|
2010-08-06 14:44:17 +08:00
|
|
|
|
pAction->initWithDuration(d);
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
|
|
|
|
|
return pAction;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCActionInterval::initWithDuration(ccTime d)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
m_fDuration = d;
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
// prevent division by 0
|
|
|
|
|
// This comparison could be in step:, but it might decrease the performance
|
2010-08-06 14:44:17 +08:00
|
|
|
|
// by 3% in heavy based action games.
|
|
|
|
|
if (m_fDuration == 0)
|
|
|
|
|
{
|
|
|
|
|
m_fDuration = FLT_EPSILON;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_elapsed = 0;
|
|
|
|
|
m_bFirstTick = true;
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
|
CCObject* CCActionInterval::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCActionInterval* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCActionInterval*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// action's base class , must be called using __super::copyWithZone(), after overriding from derived class
|
2011-11-28 17:28:43 +08:00
|
|
|
|
CCAssert(0, "");
|
2011-03-19 10:34:26 +08:00
|
|
|
|
|
|
|
|
|
pCopy = new CCActionInterval();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CCFiniteTimeAction::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration);
|
|
|
|
|
|
2010-08-06 14:44:17 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
bool CCActionInterval::isDone(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 11:46:35 +08:00
|
|
|
|
return m_elapsed >= m_fDuration;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
void CCActionInterval::step(ccTime dt)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
if (m_bFirstTick)
|
|
|
|
|
{
|
|
|
|
|
m_bFirstTick = false;
|
|
|
|
|
m_elapsed = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_elapsed += dt;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-10 17:20:28 +08:00
|
|
|
|
// update(min(1, m_elapsed/m_fDuration));
|
|
|
|
|
update(1 > m_elapsed/m_fDuration ? m_elapsed/m_fDuration : 1);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
void CCActionInterval::setAmplitudeRate(CGFloat amp)
|
2010-08-17 11:43:10 +08:00
|
|
|
|
{
|
2011-06-10 17:51:37 +08:00
|
|
|
|
CC_UNUSED_PARAM(amp);
|
2010-08-17 11:43:10 +08:00
|
|
|
|
// Abstract class needs implementation
|
2011-11-28 17:28:43 +08:00
|
|
|
|
CCAssert(0, "");
|
2010-08-17 11:43:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CGFloat CCActionInterval::getAmplitudeRate(void)
|
2010-08-17 11:43:10 +08:00
|
|
|
|
{
|
|
|
|
|
// Abstract class needs implementation
|
2011-11-28 17:28:43 +08:00
|
|
|
|
CCAssert(0, "");
|
2010-08-17 11:43:10 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
void CCActionInterval::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-09-02 14:54:42 +08:00
|
|
|
|
CCFiniteTimeAction::startWithTarget(pTarget);
|
2010-08-06 14:44:17 +08:00
|
|
|
|
m_elapsed = 0.0f;
|
|
|
|
|
m_bFirstTick = true;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCActionInterval::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
/*
|
2011-03-19 10:34:26 +08:00
|
|
|
|
NSException* myException = [NSException
|
|
|
|
|
exceptionWithName:@"ReverseActionNotImplemented"
|
|
|
|
|
reason:@"Reverse Action not implemented"
|
|
|
|
|
userInfo:nil];
|
2010-08-06 14:44:17 +08:00
|
|
|
|
@throw myException;
|
|
|
|
|
*/
|
2010-08-06 10:51:40 +08:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// Sequence
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCSequence* CCSequence::actionOneTwo(CCFiniteTimeAction *pActionOne, CCFiniteTimeAction *pActionTwo)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
CCSequence *pSequence = new CCSequence();
|
|
|
|
|
pSequence->initOneTwo(pActionOne, pActionTwo);
|
|
|
|
|
pSequence->autorelease();
|
|
|
|
|
|
|
|
|
|
return pSequence;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCFiniteTimeAction* CCSequence::actions(CCFiniteTimeAction *pAction1, ...)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
va_list params;
|
|
|
|
|
va_start(params, pAction1);
|
|
|
|
|
|
|
|
|
|
CCFiniteTimeAction *pNow;
|
|
|
|
|
CCFiniteTimeAction *pPrev = pAction1;
|
|
|
|
|
|
|
|
|
|
while (pAction1)
|
|
|
|
|
{
|
|
|
|
|
pNow = va_arg(params, CCFiniteTimeAction*);
|
|
|
|
|
if (pNow)
|
|
|
|
|
{
|
|
|
|
|
pPrev = actionOneTwo(pPrev, pNow);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
va_end(params);
|
|
|
|
|
return pPrev;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-07-11 15:25:02 +08:00
|
|
|
|
CCFiniteTimeAction* CCSequence::actionsWithArray(CCArray *actions)
|
|
|
|
|
{
|
|
|
|
|
CCFiniteTimeAction* prev = (CCFiniteTimeAction*)actions->objectAtIndex(0);
|
|
|
|
|
|
|
|
|
|
for (unsigned int i = 1; i < actions->count(); ++i)
|
|
|
|
|
{
|
|
|
|
|
prev = actionOneTwo(prev, (CCFiniteTimeAction*)actions->objectAtIndex(i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return prev;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCSequence::initOneTwo(CCFiniteTimeAction *pActionOne, CCFiniteTimeAction *pActionTwo)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-11-28 17:28:43 +08:00
|
|
|
|
CCAssert(pActionOne != NULL, "");
|
|
|
|
|
CCAssert(pActionTwo != NULL, "");
|
2010-08-06 14:44:17 +08:00
|
|
|
|
|
|
|
|
|
ccTime d = pActionOne->getDuration() + pActionTwo->getDuration();
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::initWithDuration(d);
|
2010-08-06 14:44:17 +08:00
|
|
|
|
|
|
|
|
|
m_pActions[0] = pActionOne;
|
|
|
|
|
pActionOne->retain();
|
|
|
|
|
|
|
|
|
|
m_pActions[1] = pActionTwo;
|
|
|
|
|
pActionTwo->retain();
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
|
CCObject* CCSequence::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCSequence* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCSequence*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCSequence();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initOneTwo((CCFiniteTimeAction*)(m_pActions[0]->copy()->autorelease()),
|
|
|
|
|
(CCFiniteTimeAction*)(m_pActions[1]->copy()->autorelease()));
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-06 14:44:17 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCSequence::~CCSequence(void)
|
|
|
|
|
{
|
2011-04-01 16:06:53 +08:00
|
|
|
|
CC_SAFE_RELEASE(m_pActions[0]);
|
|
|
|
|
CC_SAFE_RELEASE(m_pActions[1]);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCSequence::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2010-08-06 14:44:17 +08:00
|
|
|
|
m_split = m_pActions[0]->getDuration() / m_fDuration;
|
|
|
|
|
m_last = -1;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCSequence::stop(void)
|
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
m_pActions[0]->stop();
|
|
|
|
|
m_pActions[1]->stop();
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::stop();
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCSequence::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
int found = 0;
|
|
|
|
|
ccTime new_t = 0.0f;
|
|
|
|
|
|
|
|
|
|
if (time >= m_split)
|
|
|
|
|
{
|
|
|
|
|
found = 1;
|
|
|
|
|
if (m_split == 1)
|
|
|
|
|
{
|
|
|
|
|
new_t = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
new_t = (time - m_split) / (1 - m_split);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
found = 0;
|
|
|
|
|
if (m_split != 0)
|
|
|
|
|
{
|
|
|
|
|
new_t = time / m_split;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
new_t = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_last == -1 && found == 1)
|
|
|
|
|
{
|
|
|
|
|
m_pActions[0]->startWithTarget(m_pTarget);
|
|
|
|
|
m_pActions[0]->update(1.0f);
|
|
|
|
|
m_pActions[0]->stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_last != found)
|
|
|
|
|
{
|
|
|
|
|
if (m_last != -1)
|
|
|
|
|
{
|
2010-08-06 15:48:53 +08:00
|
|
|
|
m_pActions[m_last]->update(1.0f);
|
|
|
|
|
m_pActions[m_last]->stop();
|
2010-08-06 14:44:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_pActions[found]->startWithTarget(m_pTarget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_pActions[found]->update(new_t);
|
|
|
|
|
m_last = found;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCSequence::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
return CCSequence::actionOneTwo(m_pActions[1]->reverse(), m_pActions[0]->reverse());
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// Repeat
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCRepeat* CCRepeat::actionWithAction(CCFiniteTimeAction *pAction, unsigned int times)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
CCRepeat* pRepeat = new CCRepeat();
|
|
|
|
|
pRepeat->initWithAction(pAction, times);
|
|
|
|
|
pRepeat->autorelease();
|
|
|
|
|
|
|
|
|
|
return pRepeat;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCRepeat::initWithAction(CCFiniteTimeAction *pAction, unsigned int times)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
ccTime d = pAction->getDuration() * times;
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(d))
|
2010-08-06 14:44:17 +08:00
|
|
|
|
{
|
|
|
|
|
m_uTimes = times;
|
2011-07-01 15:08:23 +08:00
|
|
|
|
m_pInnerAction = pAction;
|
2010-08-06 14:44:17 +08:00
|
|
|
|
pAction->retain();
|
|
|
|
|
|
|
|
|
|
m_uTotal = 0;
|
2010-08-11 14:03:46 +08:00
|
|
|
|
|
|
|
|
|
return true;
|
2010-08-06 14:44:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCRepeat::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCRepeat* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCRepeat*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCRepeat();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2011-07-01 15:08:23 +08:00
|
|
|
|
pCopy->initWithAction((CCFiniteTimeAction*)(m_pInnerAction->copy()->autorelease()), m_uTimes);
|
2011-03-19 10:34:26 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-06 14:44:17 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCRepeat::~CCRepeat(void)
|
|
|
|
|
{
|
2011-07-01 15:08:23 +08:00
|
|
|
|
CC_SAFE_RELEASE(m_pInnerAction);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCRepeat::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
m_uTotal = 0;
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2011-07-01 15:08:23 +08:00
|
|
|
|
m_pInnerAction->startWithTarget(pTarget);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCRepeat::stop(void)
|
|
|
|
|
{
|
2011-07-01 15:08:23 +08:00
|
|
|
|
m_pInnerAction->stop();
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::stop();
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
// issue #80. Instead of hooking step:, hook update: since it can be called by any
|
2010-08-06 10:51:40 +08:00
|
|
|
|
// container action like Repeat, Sequence, AccelDeccel, etc..
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCRepeat::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
ccTime t = time * m_uTimes;
|
|
|
|
|
if (t > m_uTotal + 1)
|
|
|
|
|
{
|
2011-07-01 15:08:23 +08:00
|
|
|
|
m_pInnerAction->update(1.0f);
|
2010-08-06 14:44:17 +08:00
|
|
|
|
m_uTotal++;
|
2011-07-01 15:08:23 +08:00
|
|
|
|
m_pInnerAction->stop();
|
|
|
|
|
m_pInnerAction->startWithTarget(m_pTarget);
|
2010-08-06 14:44:17 +08:00
|
|
|
|
|
|
|
|
|
// repeat is over?
|
|
|
|
|
if (m_uTotal == m_uTimes)
|
|
|
|
|
{
|
|
|
|
|
// so, set it in the original position
|
2011-07-01 15:08:23 +08:00
|
|
|
|
m_pInnerAction->update(0);
|
2010-08-06 14:44:17 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
// no ? start next repeat with the right update
|
2010-08-06 14:44:17 +08:00
|
|
|
|
// to prevent jerk (issue #390)
|
2011-07-01 15:08:23 +08:00
|
|
|
|
m_pInnerAction->update(t - m_uTotal);
|
2010-08-06 14:44:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
float r = fmodf(t, 1.0f);
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
// fix last repeat position
|
2010-08-06 14:44:17 +08:00
|
|
|
|
// else it could be 0.
|
|
|
|
|
if (time == 1.0f)
|
|
|
|
|
{
|
|
|
|
|
r = 1.0f;
|
|
|
|
|
m_uTotal++; // this is the added line
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-10 17:20:28 +08:00
|
|
|
|
// m_pOther->update(min(r, 1));
|
2011-07-01 15:08:23 +08:00
|
|
|
|
m_pInnerAction->update(r > 1 ? 1 : r);
|
2010-08-06 14:44:17 +08:00
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCRepeat::isDone(void)
|
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
return m_uTotal == m_uTimes;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCRepeat::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-07-01 15:08:23 +08:00
|
|
|
|
return CCRepeat::actionWithAction(m_pInnerAction->reverse(), m_uTimes);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// RepeatForever
|
|
|
|
|
//
|
|
|
|
|
CCRepeatForever::~CCRepeatForever()
|
|
|
|
|
{
|
2011-07-01 15:08:23 +08:00
|
|
|
|
CC_SAFE_RELEASE(m_pInnerAction);
|
2011-03-19 10:34:26 +08:00
|
|
|
|
}
|
|
|
|
|
CCRepeatForever *CCRepeatForever::actionWithAction(CCActionInterval *pAction)
|
|
|
|
|
{
|
|
|
|
|
CCRepeatForever *pRet = new CCRepeatForever();
|
2010-08-28 18:00:38 +08:00
|
|
|
|
if (pRet && pRet->initWithAction(pAction))
|
|
|
|
|
{
|
|
|
|
|
pRet->autorelease();
|
|
|
|
|
return pRet;
|
|
|
|
|
}
|
2011-03-07 17:11:57 +08:00
|
|
|
|
CC_SAFE_DELETE(pRet);
|
2010-08-28 18:00:38 +08:00
|
|
|
|
return NULL;
|
2011-03-19 10:34:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCRepeatForever::initWithAction(CCActionInterval *pAction)
|
|
|
|
|
{
|
2011-11-28 17:28:43 +08:00
|
|
|
|
CCAssert(pAction != NULL, "");
|
2011-03-19 10:34:26 +08:00
|
|
|
|
pAction->retain();
|
2011-07-01 15:08:23 +08:00
|
|
|
|
m_pInnerAction = pAction;
|
2011-03-19 10:34:26 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
CCObject* CCRepeatForever::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCRepeatForever* pRet = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject) //in case of being called at sub class
|
|
|
|
|
{
|
|
|
|
|
pRet = (CCRepeatForever*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pRet = new CCRepeatForever();
|
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
|
|
|
|
}
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
// win32 : use the m_pOther's copy object.
|
2011-07-01 15:08:23 +08:00
|
|
|
|
pRet->initWithAction((CCActionInterval*)(m_pInnerAction->copy()->autorelease()));
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-28 18:00:38 +08:00
|
|
|
|
return pRet;
|
|
|
|
|
}
|
2011-03-19 10:34:26 +08:00
|
|
|
|
|
|
|
|
|
void CCRepeatForever::startWithTarget(CCNode* pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2011-07-01 15:08:23 +08:00
|
|
|
|
m_pInnerAction->startWithTarget(pTarget);
|
2011-03-19 10:34:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCRepeatForever::step(ccTime dt)
|
|
|
|
|
{
|
2011-07-01 15:08:23 +08:00
|
|
|
|
m_pInnerAction->step(dt);
|
|
|
|
|
if (m_pInnerAction->isDone())
|
2010-08-28 18:00:38 +08:00
|
|
|
|
{
|
2011-07-01 15:08:23 +08:00
|
|
|
|
ccTime diff = dt + m_pInnerAction->getDuration() - m_pInnerAction->getElapsed();
|
|
|
|
|
m_pInnerAction->startWithTarget(m_pTarget);
|
2010-08-28 18:00:38 +08:00
|
|
|
|
// to prevent jerk. issue #390
|
2011-07-01 15:08:23 +08:00
|
|
|
|
m_pInnerAction->step(diff);
|
2010-08-28 18:00:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
bool CCRepeatForever::isDone()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval *CCRepeatForever::reverse()
|
|
|
|
|
{
|
2011-07-01 15:08:23 +08:00
|
|
|
|
return (CCActionInterval*)(CCRepeatForever::actionWithAction(m_pInnerAction->reverse()));
|
2011-03-19 10:34:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Spawn
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCFiniteTimeAction* CCSpawn::actions(CCFiniteTimeAction *pAction1, ...)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
va_list params;
|
|
|
|
|
va_start(params, pAction1);
|
|
|
|
|
|
|
|
|
|
CCFiniteTimeAction *pNow;
|
|
|
|
|
CCFiniteTimeAction *pPrev = pAction1;
|
|
|
|
|
|
|
|
|
|
while (pAction1)
|
|
|
|
|
{
|
|
|
|
|
pNow = va_arg(params, CCFiniteTimeAction*);
|
|
|
|
|
if (pNow)
|
|
|
|
|
{
|
|
|
|
|
pPrev = actionOneTwo(pPrev, pNow);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
va_end(params);
|
|
|
|
|
return pPrev;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCFiniteTimeAction* CCSpawn::actionsWithArray(CCArray *actions)
|
2011-07-11 15:25:02 +08:00
|
|
|
|
{
|
|
|
|
|
CCFiniteTimeAction* prev = (CCFiniteTimeAction*)actions->objectAtIndex(0);
|
|
|
|
|
|
|
|
|
|
for (unsigned int i = 1; i < actions->count(); ++i)
|
|
|
|
|
{
|
|
|
|
|
prev = actionOneTwo(prev, (CCFiniteTimeAction*)actions->objectAtIndex(i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return prev;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCSpawn* CCSpawn::actionOneTwo(CCFiniteTimeAction *pAction1, CCFiniteTimeAction *pAction2)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
CCSpawn *pSpawn = new CCSpawn();
|
|
|
|
|
pSpawn->initOneTwo(pAction1, pAction2);
|
|
|
|
|
pSpawn->autorelease();
|
|
|
|
|
|
|
|
|
|
return pSpawn;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
bool CCSpawn:: initOneTwo(CCFiniteTimeAction *pAction1, CCFiniteTimeAction *pAction2)
|
2010-08-06 14:44:17 +08:00
|
|
|
|
{
|
2011-11-28 17:28:43 +08:00
|
|
|
|
CCAssert(pAction1 != NULL, "");
|
|
|
|
|
CCAssert(pAction2 != NULL, "");
|
2010-08-06 14:44:17 +08:00
|
|
|
|
|
2011-07-08 15:28:13 +08:00
|
|
|
|
bool bRet = false;
|
|
|
|
|
|
2010-08-06 14:44:17 +08:00
|
|
|
|
ccTime d1 = pAction1->getDuration();
|
|
|
|
|
ccTime d2 = pAction2->getDuration();
|
|
|
|
|
|
2011-07-08 15:28:13 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(MAX(d1, d2)))
|
|
|
|
|
{
|
|
|
|
|
m_pOne = pAction1;
|
|
|
|
|
m_pTwo = pAction2;
|
2010-08-06 14:44:17 +08:00
|
|
|
|
|
2011-07-08 15:28:13 +08:00
|
|
|
|
if (d1 > d2)
|
|
|
|
|
{
|
|
|
|
|
m_pTwo = CCSequence::actionOneTwo(pAction2, CCDelayTime::actionWithDuration(d1 - d2));
|
|
|
|
|
} else
|
|
|
|
|
if (d1 < d2)
|
|
|
|
|
{
|
|
|
|
|
m_pOne = CCSequence::actionOneTwo(pAction1, CCDelayTime::actionWithDuration(d2 - d1));
|
|
|
|
|
}
|
2010-08-06 14:44:17 +08:00
|
|
|
|
|
2011-07-08 15:28:13 +08:00
|
|
|
|
m_pOne->retain();
|
|
|
|
|
m_pTwo->retain();
|
|
|
|
|
|
|
|
|
|
bRet = true;
|
2010-08-06 14:44:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-07-08 15:28:13 +08:00
|
|
|
|
|
|
|
|
|
return bRet;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCSpawn::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCSpawn* pCopy = NULL;
|
|
|
|
|
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCSpawn*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCSpawn();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initOneTwo((CCFiniteTimeAction*)(m_pOne->copy()->autorelease()),
|
|
|
|
|
(CCFiniteTimeAction*)(m_pTwo->copy()->autorelease()));
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-06 14:44:17 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCSpawn::~CCSpawn(void)
|
|
|
|
|
{
|
2011-04-01 16:06:53 +08:00
|
|
|
|
CC_SAFE_RELEASE(m_pOne);
|
|
|
|
|
CC_SAFE_RELEASE(m_pTwo);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCSpawn::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2010-08-06 14:44:17 +08:00
|
|
|
|
m_pOne->startWithTarget(pTarget);
|
|
|
|
|
m_pTwo->startWithTarget(pTarget);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCSpawn::stop(void)
|
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
m_pOne->stop();
|
|
|
|
|
m_pTwo->stop();
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::stop();
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCSpawn::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-09-07 15:39:15 +08:00
|
|
|
|
if (m_pOne)
|
|
|
|
|
{
|
|
|
|
|
m_pOne->update(time);
|
|
|
|
|
}
|
|
|
|
|
if (m_pTwo)
|
|
|
|
|
{
|
|
|
|
|
m_pTwo->update(time);
|
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCSpawn::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
return CCSpawn::actionOneTwo(m_pOne->reverse(), m_pTwo->reverse());
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// RotateTo
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCRotateTo* CCRotateTo::actionWithDuration(ccTime duration, float fDeltaAngle)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 14:44:17 +08:00
|
|
|
|
CCRotateTo* pRotateTo = new CCRotateTo();
|
|
|
|
|
pRotateTo->initWithDuration(duration, fDeltaAngle);
|
|
|
|
|
pRotateTo->autorelease();
|
|
|
|
|
|
|
|
|
|
return pRotateTo;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCRotateTo::initWithDuration(ccTime duration, float fDeltaAngle)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
2010-08-06 14:44:17 +08:00
|
|
|
|
{
|
|
|
|
|
m_fDstAngle = fDeltaAngle;
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-06 14:44:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCRotateTo::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCRotateTo* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCRotateTo*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCRotateTo();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_fDstAngle);
|
|
|
|
|
|
|
|
|
|
//Action *copy = [[[self class] allocWithZone: zone] initWithDuration:[self duration] angle: angle];
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-06 14:44:17 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCRotateTo::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2010-08-06 14:44:17 +08:00
|
|
|
|
|
2010-08-30 15:06:08 +08:00
|
|
|
|
m_fStartAngle = pTarget->getRotation();
|
2010-08-06 14:44:17 +08:00
|
|
|
|
|
|
|
|
|
if (m_fStartAngle > 0)
|
|
|
|
|
{
|
|
|
|
|
m_fStartAngle = fmodf(m_fStartAngle, 360.0f);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_fStartAngle = fmodf(m_fStartAngle, -360.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_fDiffAngle = m_fDstAngle - m_fStartAngle;
|
|
|
|
|
if (m_fDiffAngle > 180)
|
|
|
|
|
{
|
|
|
|
|
m_fDiffAngle -= 360;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_fDiffAngle < -180)
|
|
|
|
|
{
|
|
|
|
|
m_fDiffAngle += 360;
|
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCRotateTo::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-09-07 15:39:15 +08:00
|
|
|
|
if (m_pTarget)
|
|
|
|
|
{
|
|
|
|
|
m_pTarget->setRotation(m_fStartAngle + m_fDiffAngle * time);
|
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// RotateBy
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCRotateBy* CCRotateBy::actionWithDuration(ccTime duration, float fDeltaAngle)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 15:48:53 +08:00
|
|
|
|
CCRotateBy *pRotateBy = new CCRotateBy();
|
|
|
|
|
pRotateBy->initWithDuration(duration, fDeltaAngle);
|
|
|
|
|
pRotateBy->autorelease();
|
|
|
|
|
|
|
|
|
|
return pRotateBy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCRotateBy::initWithDuration(ccTime duration, float fDeltaAngle)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
2010-08-06 15:48:53 +08:00
|
|
|
|
{
|
|
|
|
|
m_fAngle = fDeltaAngle;
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-06 15:48:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCRotateBy::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCRotateBy* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCRotateBy*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCRotateBy();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_fAngle);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-06 15:48:53 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCRotateBy::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2010-08-30 15:06:08 +08:00
|
|
|
|
m_fStartAngle = pTarget->getRotation();
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCRotateBy::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 15:48:53 +08:00
|
|
|
|
// XXX: shall I add % 360
|
2010-09-07 15:39:15 +08:00
|
|
|
|
if (m_pTarget)
|
|
|
|
|
{
|
|
|
|
|
m_pTarget->setRotation(m_fStartAngle + m_fAngle * time);
|
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCRotateBy::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 15:48:53 +08:00
|
|
|
|
return CCRotateBy::actionWithDuration(m_fDuration, -m_fAngle);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// MoveTo
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCMoveTo* CCMoveTo::actionWithDuration(ccTime duration, const CCPoint& position)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 15:48:53 +08:00
|
|
|
|
CCMoveTo *pMoveTo = new CCMoveTo();
|
|
|
|
|
pMoveTo->initWithDuration(duration, position);
|
|
|
|
|
pMoveTo->autorelease();
|
|
|
|
|
|
|
|
|
|
return pMoveTo;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCMoveTo::initWithDuration(ccTime duration, const CCPoint& position)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
2010-08-06 15:48:53 +08:00
|
|
|
|
{
|
|
|
|
|
m_endPosition = position;
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-06 15:48:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCMoveTo::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCMoveTo* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCMoveTo*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCMoveTo();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_endPosition);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-06 15:48:53 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCMoveTo::startWithTarget(CCNode *pTarget)
|
2010-08-06 14:44:17 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2010-08-30 15:06:08 +08:00
|
|
|
|
m_startPosition = pTarget->getPosition();
|
2010-08-06 15:48:53 +08:00
|
|
|
|
m_delta = ccpSub(m_endPosition, m_startPosition);
|
2010-08-06 14:44:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCMoveTo::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-09-07 15:39:15 +08:00
|
|
|
|
if (m_pTarget)
|
|
|
|
|
{
|
|
|
|
|
m_pTarget->setPosition(ccp(m_startPosition.x + m_delta.x * time,
|
|
|
|
|
m_startPosition.y + m_delta.y * time));
|
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// MoveBy
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCMoveBy* CCMoveBy::actionWithDuration(ccTime duration, const CCPoint& position)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-06 15:48:53 +08:00
|
|
|
|
CCMoveBy *pMoveBy = new CCMoveBy();
|
|
|
|
|
pMoveBy->initWithDuration(duration, position);
|
|
|
|
|
pMoveBy->autorelease();
|
|
|
|
|
|
|
|
|
|
return pMoveBy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCMoveBy::initWithDuration(ccTime duration, const CCPoint& position)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
2010-08-06 15:48:53 +08:00
|
|
|
|
{
|
|
|
|
|
m_delta = position;
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-06 15:48:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCMoveBy::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCMoveBy* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCMoveBy*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCMoveBy();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCMoveTo::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_delta);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-06 15:48:53 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCMoveBy::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
|
CCPoint dTmp = m_delta;
|
2010-09-02 14:54:42 +08:00
|
|
|
|
CCMoveTo::startWithTarget(pTarget);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
m_delta = dTmp;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCMoveBy::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return CCMoveBy::actionWithDuration(m_fDuration, ccp(-m_delta.x, -m_delta.y));
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-07-01 15:08:23 +08:00
|
|
|
|
//
|
|
|
|
|
// CCSkewTo
|
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCSkewTo* CCSkewTo::actionWithDuration(ccTime t, float sx, float sy)
|
2011-07-01 15:08:23 +08:00
|
|
|
|
{
|
|
|
|
|
CCSkewTo *pSkewTo = new CCSkewTo();
|
|
|
|
|
if (pSkewTo)
|
|
|
|
|
{
|
|
|
|
|
if (pSkewTo->initWithDuration(t, sx, sy))
|
|
|
|
|
{
|
|
|
|
|
pSkewTo->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_DELETE(pSkewTo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pSkewTo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCSkewTo::initWithDuration(ccTime t, float sx, float sy)
|
|
|
|
|
{
|
|
|
|
|
bool bRet = false;
|
|
|
|
|
|
|
|
|
|
if (CCActionInterval::initWithDuration(t))
|
|
|
|
|
{
|
|
|
|
|
m_fEndSkewX = sx;
|
|
|
|
|
m_fEndSkewY = sy;
|
|
|
|
|
|
|
|
|
|
bRet = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCObject* CCSkewTo::copyWithZone(CCZone* pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCSkewTo* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCSkewTo*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCSkewTo();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_fEndSkewX, m_fEndSkewY);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCSkewTo::startWithTarget(CCNode *pTarget)
|
2011-07-01 15:08:23 +08:00
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
|
|
|
|
|
|
|
|
|
m_fStartSkewX = pTarget->getSkewX();
|
|
|
|
|
|
|
|
|
|
if (m_fStartSkewX > 0)
|
|
|
|
|
{
|
|
|
|
|
m_fStartSkewX = fmodf(m_fStartSkewX, 180.f);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_fStartSkewX = fmodf(m_fStartSkewX, -180.f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_fDeltaX = m_fEndSkewX - m_fStartSkewX;
|
|
|
|
|
|
|
|
|
|
if (m_fDeltaX > 180)
|
|
|
|
|
{
|
|
|
|
|
m_fDeltaX -= 360;
|
|
|
|
|
}
|
|
|
|
|
if (m_fDeltaX < -180)
|
|
|
|
|
{
|
|
|
|
|
m_fDeltaX += 360;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-24 15:02:40 +08:00
|
|
|
|
m_fStartSkewY = pTarget->getSkewY();
|
2011-07-01 15:08:23 +08:00
|
|
|
|
|
|
|
|
|
if (m_fStartSkewY > 0)
|
|
|
|
|
{
|
|
|
|
|
m_fStartSkewY = fmodf(m_fStartSkewY, 360.f);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_fStartSkewY = fmodf(m_fStartSkewY, -360.f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_fDeltaY = m_fEndSkewY - m_fStartSkewY;
|
|
|
|
|
|
|
|
|
|
if (m_fDeltaY > 180)
|
|
|
|
|
{
|
|
|
|
|
m_fDeltaY -= 360;
|
|
|
|
|
}
|
|
|
|
|
if (m_fDeltaY < -180)
|
|
|
|
|
{
|
|
|
|
|
m_fDeltaY += 360;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCSkewTo::update(ccTime t)
|
|
|
|
|
{
|
|
|
|
|
m_pTarget->setSkewX(m_fStartSkewX + m_fDeltaX * t);
|
|
|
|
|
m_pTarget->setSkewY(m_fStartSkewY + m_fDeltaY * t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCSkewTo::CCSkewTo()
|
|
|
|
|
: m_fSkewX(0.0)
|
|
|
|
|
, m_fSkewY(0.0)
|
|
|
|
|
, m_fStartSkewX(0.0)
|
|
|
|
|
, m_fStartSkewY(0.0)
|
|
|
|
|
, m_fEndSkewX(0.0)
|
|
|
|
|
, m_fEndSkewY(0.0)
|
|
|
|
|
, m_fDeltaX(0.0)
|
|
|
|
|
, m_fDeltaY(0.0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// CCSkewBy
|
|
|
|
|
//
|
|
|
|
|
CCSkewBy* CCSkewBy::actionWithDuration(ccTime t, float sx, float sy)
|
|
|
|
|
{
|
|
|
|
|
CCSkewBy *pSkewBy = new CCSkewBy();
|
|
|
|
|
if (pSkewBy)
|
|
|
|
|
{
|
|
|
|
|
if (pSkewBy->initWithDuration(t, sx, sy))
|
|
|
|
|
{
|
|
|
|
|
pSkewBy->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_DELETE(pSkewBy);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pSkewBy;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCSkewBy::initWithDuration(ccTime t, float deltaSkewX, float deltaSkewY)
|
2011-07-01 15:08:23 +08:00
|
|
|
|
{
|
|
|
|
|
bool bRet = false;
|
|
|
|
|
|
|
|
|
|
if (CCSkewTo::initWithDuration(t, deltaSkewX, deltaSkewY))
|
|
|
|
|
{
|
|
|
|
|
m_fSkewX = deltaSkewX;
|
|
|
|
|
m_fSkewY = deltaSkewY;
|
|
|
|
|
|
|
|
|
|
bRet = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCSkewBy::startWithTarget(CCNode *pTarget)
|
2011-07-01 15:08:23 +08:00
|
|
|
|
{
|
|
|
|
|
CCSkewTo::startWithTarget(pTarget);
|
|
|
|
|
m_fDeltaX = m_fSkewX;
|
|
|
|
|
m_fDeltaY = m_fSkewY;
|
|
|
|
|
m_fEndSkewX = m_fStartSkewX + m_fDeltaX;
|
|
|
|
|
m_fEndSkewY = m_fStartSkewY + m_fDeltaY;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 15:41:42 +08:00
|
|
|
|
CCActionInterval* CCSkewBy::reverse()
|
2011-07-01 15:08:23 +08:00
|
|
|
|
{
|
|
|
|
|
return actionWithDuration(m_fDuration, -m_fSkewX, -m_fSkewY);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// JumpBy
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCJumpBy* CCJumpBy::actionWithDuration(ccTime duration, const CCPoint& position, ccTime height, unsigned int jumps)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
CCJumpBy *pJumpBy = new CCJumpBy();
|
|
|
|
|
pJumpBy->initWithDuration(duration, position, height, jumps);
|
|
|
|
|
pJumpBy->autorelease();
|
|
|
|
|
|
|
|
|
|
return pJumpBy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCJumpBy::initWithDuration(ccTime duration, const CCPoint& position, ccTime height, unsigned int jumps)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
2010-08-09 16:27:36 +08:00
|
|
|
|
{
|
|
|
|
|
m_delta = position;
|
2010-08-12 17:01:51 +08:00
|
|
|
|
m_height = height;
|
2010-08-09 16:27:36 +08:00
|
|
|
|
m_nJumps = jumps;
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-09 16:27:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCJumpBy::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCJumpBy* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCJumpBy*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCJumpBy();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_delta, m_height, m_nJumps);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCJumpBy::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2010-08-30 15:06:08 +08:00
|
|
|
|
m_startPosition = pTarget->getPosition();
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCJumpBy::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
// parabolic jump (since v0.8.2)
|
2010-09-07 15:39:15 +08:00
|
|
|
|
if (m_pTarget)
|
|
|
|
|
{
|
|
|
|
|
ccTime frac = fmodf(time * m_nJumps, 1.0f);
|
|
|
|
|
ccTime y = m_height * 4 * frac * (1 - frac);
|
|
|
|
|
y += m_delta.y * time;
|
|
|
|
|
ccTime x = m_delta.x * time;
|
|
|
|
|
m_pTarget->setPosition(ccp(m_startPosition.x + x, m_startPosition.y + y));
|
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCJumpBy::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return CCJumpBy::actionWithDuration(m_fDuration, ccp(-m_delta.x, -m_delta.y),
|
|
|
|
|
m_height, m_nJumps);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// JumpTo
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCJumpTo* CCJumpTo::actionWithDuration(ccTime duration, const CCPoint& position, ccTime height, int jumps)
|
2010-08-11 14:03:46 +08:00
|
|
|
|
{
|
|
|
|
|
CCJumpTo *pJumpTo = new CCJumpTo();
|
|
|
|
|
pJumpTo->initWithDuration(duration, position, height, jumps);
|
|
|
|
|
pJumpTo->autorelease();
|
|
|
|
|
|
|
|
|
|
return pJumpTo;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
|
CCObject* CCJumpTo::copyWithZone(CCZone* pZone)
|
2010-08-11 14:03:46 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCJumpTo* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCJumpTo*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCJumpTo();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCJumpBy::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_delta, m_height, m_nJumps);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCJumpTo::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-09-02 14:54:42 +08:00
|
|
|
|
CCJumpBy::startWithTarget(pTarget);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
m_delta = ccp(m_delta.x - m_startPosition.x, m_delta.y - m_startPosition.y);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
// Bezier cubic formula:
|
|
|
|
|
// ((1 - t) + t)3 = 1
|
|
|
|
|
// Expands to<74><6F>
|
|
|
|
|
// (1 - t)3 + 3t(1-t)2 + 3t2(1 - t) + t3 = 1
|
|
|
|
|
static inline float bezierat( float a, float b, float c, float d, ccTime t )
|
|
|
|
|
{
|
|
|
|
|
return (powf(1-t,3) * a +
|
|
|
|
|
3*t*(powf(1-t,2))*b +
|
|
|
|
|
3*powf(t,2)*(1-t)*c +
|
|
|
|
|
powf(t,3)*d );
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// BezierBy
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCBezierBy* CCBezierBy::actionWithDuration(ccTime t, const ccBezierConfig& c)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
CCBezierBy *pBezierBy = new CCBezierBy();
|
|
|
|
|
pBezierBy->initWithDuration(t, c);
|
|
|
|
|
pBezierBy->autorelease();
|
|
|
|
|
|
|
|
|
|
return pBezierBy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCBezierBy::initWithDuration(ccTime t, const ccBezierConfig& c)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(t))
|
2010-08-09 16:27:36 +08:00
|
|
|
|
{
|
|
|
|
|
m_sConfig = c;
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-09 16:27:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCBezierBy::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2010-08-30 15:06:08 +08:00
|
|
|
|
m_startPosition = pTarget->getPosition();
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCBezierBy::copyWithZone(CCZone *pZone)
|
2010-08-06 14:44:17 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCBezierBy* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCBezierBy*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCBezierBy();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_sConfig);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 14:44:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCBezierBy::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-09-07 15:39:15 +08:00
|
|
|
|
if (m_pTarget)
|
|
|
|
|
{
|
|
|
|
|
float xa = 0;
|
|
|
|
|
float xb = m_sConfig.controlPoint_1.x;
|
|
|
|
|
float xc = m_sConfig.controlPoint_2.x;
|
|
|
|
|
float xd = m_sConfig.endPosition.x;
|
|
|
|
|
|
|
|
|
|
float ya = 0;
|
|
|
|
|
float yb = m_sConfig.controlPoint_1.y;
|
|
|
|
|
float yc = m_sConfig.controlPoint_2.y;
|
|
|
|
|
float yd = m_sConfig.endPosition.y;
|
|
|
|
|
|
|
|
|
|
float x = bezierat(xa, xb, xc, xd, time);
|
|
|
|
|
float y = bezierat(ya, yb, yc, yd, time);
|
|
|
|
|
m_pTarget->setPosition(ccpAdd(m_startPosition, ccp(x, y)));
|
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCBezierBy::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
ccBezierConfig r;
|
|
|
|
|
|
|
|
|
|
r.endPosition = ccpNeg(m_sConfig.endPosition);
|
|
|
|
|
r.controlPoint_1 = ccpAdd(m_sConfig.controlPoint_2, ccpNeg(m_sConfig.endPosition));
|
|
|
|
|
r.controlPoint_2 = ccpAdd(m_sConfig.controlPoint_1, ccpNeg(m_sConfig.endPosition));
|
|
|
|
|
|
|
|
|
|
CCBezierBy *pAction = CCBezierBy::actionWithDuration(m_fDuration, r);
|
|
|
|
|
return pAction;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// BezierTo
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCBezierTo* CCBezierTo::actionWithDuration(ccTime t, const ccBezierConfig& c)
|
2010-08-11 14:03:46 +08:00
|
|
|
|
{
|
|
|
|
|
CCBezierTo *pBezierTo = new CCBezierTo();
|
|
|
|
|
pBezierTo->initWithDuration(t, c);
|
|
|
|
|
pBezierTo->autorelease();
|
|
|
|
|
|
|
|
|
|
return pBezierTo;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCBezierTo::copyWithZone(CCZone *pZone)
|
2010-08-11 14:03:46 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCBezierBy* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCBezierTo*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCBezierTo();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCBezierBy::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_sConfig);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCBezierTo::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-09-02 14:54:42 +08:00
|
|
|
|
CCBezierBy::startWithTarget(pTarget);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
m_sConfig.controlPoint_1 = ccpSub(m_sConfig.controlPoint_1, m_startPosition);
|
|
|
|
|
m_sConfig.controlPoint_2 = ccpSub(m_sConfig.controlPoint_2, m_startPosition);
|
|
|
|
|
m_sConfig.endPosition = ccpSub(m_sConfig.endPosition, m_startPosition);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// ScaleTo
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCScaleTo* CCScaleTo::actionWithDuration(ccTime duration, float s)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
CCScaleTo *pScaleTo = new CCScaleTo();
|
|
|
|
|
pScaleTo->initWithDuration(duration, s);
|
|
|
|
|
pScaleTo->autorelease();
|
|
|
|
|
|
|
|
|
|
return pScaleTo;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCScaleTo::initWithDuration(ccTime duration, float s)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
2010-08-09 16:27:36 +08:00
|
|
|
|
{
|
|
|
|
|
m_fEndScaleX = s;
|
|
|
|
|
m_fEndScaleY = s;
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-09 16:27:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCScaleTo* CCScaleTo::actionWithDuration(ccTime duration, float sx, float sy)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
CCScaleTo *pScaleTo = new CCScaleTo();
|
|
|
|
|
pScaleTo->initWithDuration(duration, sx, sy);
|
|
|
|
|
pScaleTo->autorelease();
|
|
|
|
|
|
|
|
|
|
return pScaleTo;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCScaleTo::initWithDuration(ccTime duration, float sx, float sy)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
2010-08-09 16:27:36 +08:00
|
|
|
|
{
|
|
|
|
|
m_fEndScaleX = sx;
|
|
|
|
|
m_fEndScaleY = sy;
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-09 16:27:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCScaleTo::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCScaleTo* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCScaleTo*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCScaleTo();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_fEndScaleX, m_fEndScaleY);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCScaleTo::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2010-08-30 15:06:08 +08:00
|
|
|
|
m_fStartScaleX = pTarget->getScaleX();
|
|
|
|
|
m_fStartScaleY = pTarget->getScaleY();
|
2010-08-09 16:27:36 +08:00
|
|
|
|
m_fDeltaX = m_fEndScaleX - m_fStartScaleX;
|
|
|
|
|
m_fDeltaY = m_fEndScaleY - m_fStartScaleY;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCScaleTo::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-09-07 15:39:15 +08:00
|
|
|
|
if (m_pTarget)
|
|
|
|
|
{
|
|
|
|
|
m_pTarget->setScaleX(m_fStartScaleX + m_fDeltaX * time);
|
|
|
|
|
m_pTarget->setScaleY(m_fStartScaleY + m_fDeltaY * time);
|
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// ScaleBy
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCScaleBy* CCScaleBy::actionWithDuration(ccTime duration, float s)
|
2010-08-11 14:03:46 +08:00
|
|
|
|
{
|
|
|
|
|
CCScaleBy *pScaleBy = new CCScaleBy();
|
|
|
|
|
pScaleBy->initWithDuration(duration, s);
|
|
|
|
|
pScaleBy->autorelease();
|
|
|
|
|
|
|
|
|
|
return pScaleBy;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCScaleBy* CCScaleBy::actionWithDuration(ccTime duration, float sx, float sy)
|
2010-08-11 14:03:46 +08:00
|
|
|
|
{
|
|
|
|
|
CCScaleBy *pScaleBy = new CCScaleBy();
|
|
|
|
|
pScaleBy->initWithDuration(duration, sx, sy);
|
|
|
|
|
pScaleBy->autorelease();
|
|
|
|
|
|
|
|
|
|
return pScaleBy;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCScaleBy::copyWithZone(CCZone *pZone)
|
2010-08-11 14:03:46 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCScaleTo* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCScaleBy*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCScaleBy();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCScaleTo::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_fEndScaleX, m_fEndScaleY);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCScaleBy::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-09-02 14:54:42 +08:00
|
|
|
|
CCScaleTo::startWithTarget(pTarget);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
m_fDeltaX = m_fStartScaleX * m_fEndScaleX - m_fStartScaleX;
|
|
|
|
|
m_fDeltaY = m_fStartScaleY * m_fEndScaleY - m_fStartScaleY;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 15:41:42 +08:00
|
|
|
|
CCActionInterval* CCScaleBy::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return CCScaleBy::actionWithDuration(m_fDuration, 1 / m_fEndScaleX, 1 / m_fEndScaleY);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// Blink
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCBlink* CCBlink::actionWithDuration(ccTime duration, unsigned int uBlinks)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
CCBlink *pBlink = new CCBlink();
|
|
|
|
|
pBlink->initWithDuration(duration, uBlinks);
|
|
|
|
|
pBlink->autorelease();
|
|
|
|
|
|
|
|
|
|
return pBlink;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCBlink::initWithDuration(ccTime duration, unsigned int uBlinks)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
2010-08-09 16:27:36 +08:00
|
|
|
|
{
|
|
|
|
|
m_nTimes = uBlinks;
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-09 16:27:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCBlink::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCBlink* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCBlink*)(pZone->m_pCopyObject);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCBlink();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, (unsigned int)m_nTimes);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCBlink::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-23 16:47:29 +08:00
|
|
|
|
if (m_pTarget && ! isDone())
|
2010-09-07 15:39:15 +08:00
|
|
|
|
{
|
|
|
|
|
ccTime slice = 1.0f / m_nTimes;
|
|
|
|
|
ccTime m = fmodf(time, slice);
|
|
|
|
|
m_pTarget->setIsVisible(m > slice / 2 ? true : false);
|
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCBlink::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
// return 'self'
|
|
|
|
|
return CCBlink::actionWithDuration(m_fDuration, m_nTimes);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// FadeIn
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCFadeIn* CCFadeIn::actionWithDuration(ccTime d)
|
2010-08-11 14:03:46 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCFadeIn* pAction = new CCFadeIn();
|
|
|
|
|
|
|
|
|
|
pAction->initWithDuration(d);
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return pAction;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCFadeIn::copyWithZone(CCZone *pZone)
|
2010-08-11 14:03:46 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCFadeIn* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCFadeIn*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCFadeIn();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCFadeIn::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-31 11:20:37 +08:00
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol();
|
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
|
|
|
|
pRGBAProtocol->setOpacity((GLubyte)(255 * time));
|
|
|
|
|
}
|
|
|
|
|
/*m_pTarget->setOpacity((GLubyte)(255 * time));*/
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCFadeIn::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return CCFadeOut::actionWithDuration(m_fDuration);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// FadeOut
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCFadeOut* CCFadeOut::actionWithDuration(ccTime d)
|
2010-08-11 14:03:46 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCFadeOut* pAction = new CCFadeOut();
|
|
|
|
|
|
|
|
|
|
pAction->initWithDuration(d);
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return pAction;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCFadeOut::copyWithZone(CCZone *pZone)
|
2010-08-11 14:03:46 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCFadeOut* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCFadeOut*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCFadeOut();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCFadeOut::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-31 11:20:37 +08:00
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol();
|
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
|
|
|
|
pRGBAProtocol->setOpacity(GLubyte(255 * (1 - time)));
|
|
|
|
|
}
|
|
|
|
|
/*m_pTarget->setOpacity(GLubyte(255 * (1 - time)));*/
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCFadeOut::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return CCFadeIn::actionWithDuration(m_fDuration);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// FadeTo
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCFadeTo* CCFadeTo::actionWithDuration(ccTime duration, GLubyte opacity)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
CCFadeTo *pFadeTo = new CCFadeTo();
|
|
|
|
|
pFadeTo->initWithDuration(duration, opacity);
|
|
|
|
|
pFadeTo->autorelease();
|
|
|
|
|
|
|
|
|
|
return pFadeTo;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCFadeTo::initWithDuration(ccTime duration, GLubyte opacity)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
2010-08-09 16:27:36 +08:00
|
|
|
|
{
|
|
|
|
|
m_toOpacity = opacity;
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-09 16:27:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCFadeTo::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCFadeTo* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCFadeTo*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCFadeTo();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_toOpacity);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCFadeTo::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
|
2010-08-31 11:20:37 +08:00
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = pTarget->convertToRGBAProtocol();
|
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
|
|
|
|
m_fromOpacity = pRGBAProtocol->getOpacity();
|
|
|
|
|
}
|
|
|
|
|
/*m_fromOpacity = pTarget->getOpacity();*/
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCFadeTo::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-31 11:20:37 +08:00
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol();
|
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
|
|
|
|
pRGBAProtocol->setOpacity((GLubyte)(m_fromOpacity + (m_toOpacity - m_fromOpacity) * time));
|
|
|
|
|
}
|
|
|
|
|
/*m_pTarget->setOpacity((GLubyte)(m_fromOpacity + (m_toOpacity - m_fromOpacity) * time));*/
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// TintTo
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCTintTo* CCTintTo::actionWithDuration(ccTime duration, GLubyte red, GLubyte green, GLubyte blue)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
CCTintTo *pTintTo = new CCTintTo();
|
|
|
|
|
pTintTo->initWithDuration(duration, red, green, blue);
|
|
|
|
|
pTintTo->autorelease();
|
|
|
|
|
|
|
|
|
|
return pTintTo;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCTintTo::initWithDuration(ccTime duration, GLubyte red, GLubyte green, GLubyte blue)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
2010-08-09 16:27:36 +08:00
|
|
|
|
{
|
|
|
|
|
m_to = ccc3(red, green, blue);
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-09 16:27:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCTintTo::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCTintTo* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCTintTo*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCTintTo();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_to.r, m_to.g, m_to.b);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCTintTo::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2010-08-31 11:20:37 +08:00
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol();
|
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
|
|
|
|
m_from = pRGBAProtocol->getColor();
|
|
|
|
|
}
|
|
|
|
|
/*m_from = pTarget->getColor();*/
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCTintTo::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-31 11:20:37 +08:00
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol();
|
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
|
|
|
|
pRGBAProtocol->setColor(ccc3(GLubyte(m_from.r + (m_to.r - m_from.r) * time),
|
|
|
|
|
(GLbyte)(m_from.g + (m_to.g - m_from.g) * time),
|
|
|
|
|
(GLbyte)(m_from.b + (m_to.b - m_from.b) * time)));
|
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// TintBy
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCTintBy* CCTintBy::actionWithDuration(ccTime duration, GLshort deltaRed, GLshort deltaGreen, GLshort deltaBlue)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
CCTintBy *pTintBy = new CCTintBy();
|
|
|
|
|
pTintBy->initWithDuration(duration, deltaRed, deltaGreen, deltaBlue);
|
|
|
|
|
pTintBy->autorelease();
|
|
|
|
|
|
|
|
|
|
return pTintBy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCTintBy::initWithDuration(ccTime duration, GLshort deltaRed, GLshort deltaGreen, GLshort deltaBlue)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
2010-08-09 16:27:36 +08:00
|
|
|
|
{
|
|
|
|
|
m_deltaR = deltaRed;
|
|
|
|
|
m_deltaG = deltaGreen;
|
|
|
|
|
m_deltaB = deltaBlue;
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-09 16:27:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCTintBy::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCTintBy* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCTintBy*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCTintBy();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, (GLubyte)m_deltaR, (GLubyte)m_deltaG, (GLubyte)m_deltaB);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCTintBy::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
|
2010-08-31 11:20:37 +08:00
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = pTarget->convertToRGBAProtocol();
|
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
|
|
|
|
ccColor3B color = pRGBAProtocol->getColor();
|
|
|
|
|
m_fromR = color.r;
|
|
|
|
|
m_fromG = color.g;
|
|
|
|
|
m_fromB = color.b;
|
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCTintBy::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-31 11:20:37 +08:00
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = m_pTarget->convertToRGBAProtocol();
|
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
|
|
|
|
pRGBAProtocol->setColor(ccc3((GLubyte)(m_fromR + m_deltaR * time),
|
|
|
|
|
(GLubyte)(m_fromG + m_deltaG * time),
|
|
|
|
|
(GLubyte)(m_fromB + m_deltaB * time)));
|
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCTintBy::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-12 17:01:51 +08:00
|
|
|
|
return CCTintBy::actionWithDuration(m_fDuration, -m_deltaR, -m_deltaG, -m_deltaB);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// DelayTime
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCDelayTime* CCDelayTime::actionWithDuration(ccTime d)
|
2010-08-11 14:03:46 +08:00
|
|
|
|
{
|
|
|
|
|
CCDelayTime* pAction = new CCDelayTime();
|
|
|
|
|
|
|
|
|
|
pAction->initWithDuration(d);
|
2011-03-19 10:34:26 +08:00
|
|
|
|
pAction->autorelease();
|
2010-08-11 14:03:46 +08:00
|
|
|
|
|
|
|
|
|
return pAction;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCDelayTime::copyWithZone(CCZone *pZone)
|
2010-08-11 14:03:46 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCDelayTime* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCDelayTime*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCDelayTime();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCDelayTime::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-06-10 17:51:37 +08:00
|
|
|
|
CC_UNUSED_PARAM(time);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCDelayTime::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return CCDelayTime::actionWithDuration(m_fDuration);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// ReverseTime
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCReverseTime* CCReverseTime::actionWithAction(CCFiniteTimeAction *pAction)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
// casting to prevent warnings
|
|
|
|
|
CCReverseTime *pReverseTime = new CCReverseTime();
|
|
|
|
|
pReverseTime->initWithAction(pAction);
|
|
|
|
|
pReverseTime->autorelease();
|
|
|
|
|
|
|
|
|
|
return pReverseTime;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCReverseTime::initWithAction(CCFiniteTimeAction *pAction)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-11-28 17:28:43 +08:00
|
|
|
|
CCAssert(pAction != NULL, "");
|
|
|
|
|
CCAssert(pAction != m_pOther, "");
|
2011-07-01 15:08:23 +08:00
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(pAction->getDuration()))
|
2010-08-09 16:27:36 +08:00
|
|
|
|
{
|
2011-07-01 15:08:23 +08:00
|
|
|
|
// Don't leak if action is reused
|
|
|
|
|
CC_SAFE_RELEASE(m_pOther);
|
|
|
|
|
|
2010-08-09 16:27:36 +08:00
|
|
|
|
m_pOther = pAction;
|
|
|
|
|
pAction->retain();
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-09 16:27:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCReverseTime::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCReverseTime* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCReverseTime*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCReverseTime();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithAction((CCFiniteTimeAction*)(m_pOther->copy()->autorelease()));
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-07-06 15:22:25 +08:00
|
|
|
|
CCReverseTime::CCReverseTime() : m_pOther(NULL)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-06 10:51:40 +08:00
|
|
|
|
CCReverseTime::~CCReverseTime(void)
|
|
|
|
|
{
|
2011-04-01 16:06:53 +08:00
|
|
|
|
CC_SAFE_RELEASE(m_pOther);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCReverseTime::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
m_pOther->startWithTarget(pTarget);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCReverseTime::stop(void)
|
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
m_pOther->stop();
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::stop();
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCReverseTime::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-09-07 15:39:15 +08:00
|
|
|
|
if (m_pOther)
|
|
|
|
|
{
|
|
|
|
|
m_pOther->update(1 - time);
|
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCReverseTime::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
return (CCActionInterval*)(m_pOther->copy()->autorelease());
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-19 10:34:26 +08:00
|
|
|
|
//
|
|
|
|
|
// Animate
|
2010-08-06 10:51:40 +08:00
|
|
|
|
//
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCAnimate* CCAnimate::actionWithAnimation(CCAnimation *pAnimation)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
CCAnimate *pAnimate = new CCAnimate();
|
|
|
|
|
pAnimate->initWithAnimation(pAnimation, true);
|
|
|
|
|
pAnimate->autorelease();
|
|
|
|
|
|
|
|
|
|
return pAnimate;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCAnimate::initWithAnimation(CCAnimation *pAnimation)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-11-28 17:28:43 +08:00
|
|
|
|
CCAssert(pAnimation != NULL, "");
|
2010-08-09 16:27:36 +08:00
|
|
|
|
|
|
|
|
|
return initWithAnimation(pAnimation, true);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCAnimate* CCAnimate::actionWithAnimation(CCAnimation *pAnimation, bool bRestoreOriginalFrame)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
CCAnimate *pAnimate = new CCAnimate();
|
|
|
|
|
pAnimate->initWithAnimation(pAnimation, bRestoreOriginalFrame);
|
|
|
|
|
pAnimate->autorelease();
|
|
|
|
|
|
|
|
|
|
return pAnimate;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCAnimate::initWithAnimation(CCAnimation *pAnimation, bool bRestoreOriginalFrame)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-11-28 17:28:43 +08:00
|
|
|
|
CCAssert(pAnimation, "");
|
2010-08-09 16:27:36 +08:00
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(pAnimation->getFrames()->count() * pAnimation->getDelay()))
|
2010-08-09 16:27:36 +08:00
|
|
|
|
{
|
|
|
|
|
m_bRestoreOriginalFrame = bRestoreOriginalFrame;
|
2010-09-06 10:27:38 +08:00
|
|
|
|
m_pAnimation = pAnimation;
|
2011-03-07 17:11:57 +08:00
|
|
|
|
CC_SAFE_RETAIN(m_pAnimation);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
m_pOrigFrame = NULL;
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-09 16:27:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCAnimate* CCAnimate::actionWithDuration(ccTime duration, CCAnimation *pAnimation, bool bRestoreOriginalFrame)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-08-09 16:27:36 +08:00
|
|
|
|
CCAnimate *pAnimate = new CCAnimate();
|
|
|
|
|
pAnimate->initWithDuration(duration, pAnimation, bRestoreOriginalFrame);
|
|
|
|
|
pAnimate->autorelease();
|
|
|
|
|
|
|
|
|
|
return pAnimate;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
bool CCAnimate::initWithDuration(ccTime duration, CCAnimation *pAnimation, bool bRestoreOriginalFrame)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-11-28 17:28:43 +08:00
|
|
|
|
CCAssert(pAnimation != NULL, "");
|
2010-08-09 16:27:36 +08:00
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
2010-08-09 16:27:36 +08:00
|
|
|
|
{
|
|
|
|
|
m_bRestoreOriginalFrame = bRestoreOriginalFrame;
|
|
|
|
|
m_pAnimation = pAnimation;
|
2011-03-07 17:11:57 +08:00
|
|
|
|
CC_SAFE_RETAIN(m_pAnimation);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
m_pOrigFrame = NULL;
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return true;
|
2010-08-09 16:27:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:03:46 +08:00
|
|
|
|
return false;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
CCObject* CCAnimate::copyWithZone(CCZone *pZone)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-19 10:34:26 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCAnimate* pCopy = NULL;
|
|
|
|
|
if(pZone && pZone->m_pCopyObject)
|
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
|
|
|
|
pCopy = (CCAnimate*)(pZone->m_pCopyObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCAnimate();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
pCopy->initWithDuration(m_fDuration, m_pAnimation, m_bRestoreOriginalFrame);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
return pCopy;
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCAnimate::~CCAnimate(void)
|
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
|
CC_SAFE_RELEASE(m_pAnimation);
|
|
|
|
|
CC_SAFE_RELEASE(m_pOrigFrame);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-28 12:02:10 +08:00
|
|
|
|
void CCAnimate::startWithTarget(CCNode *pTarget)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2010-08-30 15:06:08 +08:00
|
|
|
|
CCSprite *pSprite = (CCSprite*)(pTarget);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
|
CC_SAFE_RELEASE(m_pOrigFrame);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
|
|
|
|
|
if (m_bRestoreOriginalFrame)
|
|
|
|
|
{
|
|
|
|
|
m_pOrigFrame = pSprite->displayedFrame();
|
|
|
|
|
m_pOrigFrame->retain();
|
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCAnimate::stop(void)
|
|
|
|
|
{
|
2010-12-04 15:03:07 +08:00
|
|
|
|
if (m_bRestoreOriginalFrame && m_pTarget)
|
2010-08-09 16:27:36 +08:00
|
|
|
|
{
|
2010-08-30 15:06:08 +08:00
|
|
|
|
((CCSprite*)(m_pTarget))->setDisplayFrame(m_pOrigFrame);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval::stop();
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
|
void CCAnimate::update(ccTime time)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
|
CCMutableArray<CCSpriteFrame*> *pFrames = m_pAnimation->getFrames();
|
2010-08-09 16:27:36 +08:00
|
|
|
|
unsigned int numberOfFrames = pFrames->count();
|
|
|
|
|
|
2010-08-12 17:01:51 +08:00
|
|
|
|
unsigned int idx = (unsigned int)(time * numberOfFrames);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
|
|
|
|
|
if (idx >= numberOfFrames)
|
|
|
|
|
{
|
|
|
|
|
idx = numberOfFrames - 1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-30 15:06:08 +08:00
|
|
|
|
CCSprite *pSprite = (CCSprite*)(m_pTarget);
|
2010-08-09 16:27:36 +08:00
|
|
|
|
if (! pSprite->isFrameDisplayed(pFrames->getObjectAtIndex(idx)))
|
|
|
|
|
{
|
|
|
|
|
pSprite->setDisplayFrame(pFrames->getObjectAtIndex(idx));
|
|
|
|
|
}
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-22 15:43:54 +08:00
|
|
|
|
CCActionInterval* CCAnimate::reverse(void)
|
2010-08-06 10:51:40 +08:00
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
|
CCMutableArray<CCSpriteFrame*> *pOldArray = m_pAnimation->getFrames();
|
|
|
|
|
CCMutableArray<CCSpriteFrame*> *pNewArray = new CCMutableArray<CCSpriteFrame*>(pOldArray->count());
|
2010-08-09 16:27:36 +08:00
|
|
|
|
|
|
|
|
|
if (pOldArray->count() > 0)
|
|
|
|
|
{
|
|
|
|
|
CCSpriteFrame *pElement;
|
2011-03-07 17:11:57 +08:00
|
|
|
|
CCMutableArray<CCSpriteFrame*>::CCMutableArrayRevIterator iter;
|
2010-08-09 16:27:36 +08:00
|
|
|
|
for (iter = pOldArray->rbegin(); iter != pOldArray->rend(); iter++)
|
|
|
|
|
{
|
|
|
|
|
pElement = *iter;
|
|
|
|
|
if (! pElement)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-30 15:06:08 +08:00
|
|
|
|
pNewArray->addObject((CCSpriteFrame*)(pElement->copy()->autorelease()));
|
2010-08-09 16:27:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-02 15:45:27 +08:00
|
|
|
|
CCAnimation *pNewAnim = CCAnimation::animationWithFrames(pNewArray, m_pAnimation->getDelay());
|
2010-08-09 16:27:36 +08:00
|
|
|
|
|
|
|
|
|
pNewArray->release();
|
|
|
|
|
|
|
|
|
|
return CCAnimate::actionWithDuration(m_fDuration, pNewAnim, m_bRestoreOriginalFrame);
|
2010-08-06 10:51:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|