2012-04-19 14:35:52 +08:00
|
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-04-19 14:35:52 +08:00
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
|
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "CCActionInterval.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
|
#include "sprite_nodes/CCSprite.h"
|
|
|
|
|
#include "base_nodes/CCNode.h"
|
|
|
|
|
#include "support/CCPointExtension.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
#include "CCStdC.h"
|
|
|
|
|
#include "CCActionInstant.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
|
#include "cocoa/CCZone.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
2012-12-10 12:02:24 +08:00
|
|
|
|
// Extra action for making a CCSequence or CCSpawn when only adding one action to it.
|
|
|
|
|
class ExtraAction : public CCFiniteTimeAction
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static ExtraAction* create();
|
2013-06-14 08:25:14 +08:00
|
|
|
|
virtual ExtraAction* clone() const;
|
2012-12-10 12:02:24 +08:00
|
|
|
|
virtual CCObject* copyWithZone(CCZone* pZone);
|
2013-06-16 03:38:32 +08:00
|
|
|
|
virtual ExtraAction* reverse(void) const;
|
2012-12-10 14:11:42 +08:00
|
|
|
|
virtual void update(float time);
|
|
|
|
|
virtual void step(float dt);
|
2012-12-10 12:02:24 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ExtraAction* ExtraAction::create()
|
|
|
|
|
{
|
|
|
|
|
ExtraAction* pRet = new ExtraAction();
|
|
|
|
|
if (pRet)
|
|
|
|
|
{
|
|
|
|
|
pRet->autorelease();
|
|
|
|
|
}
|
|
|
|
|
return pRet;
|
|
|
|
|
}
|
2013-06-14 08:25:14 +08:00
|
|
|
|
ExtraAction* ExtraAction::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new ExtraAction(*this);
|
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
2012-12-10 12:02:24 +08:00
|
|
|
|
|
|
|
|
|
CCObject* ExtraAction::copyWithZone(CCZone* pZone)
|
|
|
|
|
{
|
2012-12-10 14:11:42 +08:00
|
|
|
|
CC_UNUSED_PARAM(pZone);
|
2012-12-10 12:02:24 +08:00
|
|
|
|
ExtraAction* pRet = new ExtraAction();
|
|
|
|
|
return pRet;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
|
ExtraAction* ExtraAction::reverse(void) const
|
2012-12-10 12:02:24 +08:00
|
|
|
|
{
|
|
|
|
|
return ExtraAction::create();
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-10 14:11:42 +08:00
|
|
|
|
void ExtraAction::update(float time)
|
|
|
|
|
{
|
|
|
|
|
CC_UNUSED_PARAM(time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExtraAction::step(float dt)
|
|
|
|
|
{
|
|
|
|
|
CC_UNUSED_PARAM(dt);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
//
|
|
|
|
|
// IntervalAction
|
|
|
|
|
//
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
bool CCActionInterval::initWithDuration(float d)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_duration = d;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
// prevent division by 0
|
|
|
|
|
// This comparison could be in step:, but it might decrease the performance
|
|
|
|
|
// by 3% in heavy based action games.
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_duration == 0)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_duration = FLT_EPSILON;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_elapsed = 0;
|
|
|
|
|
_firstTick = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCActionInterval::isDone(void)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
return _elapsed >= _duration;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCActionInterval::step(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_firstTick)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_firstTick = false;
|
|
|
|
|
_elapsed = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_elapsed += dt;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2012-05-04 16:22:50 +08:00
|
|
|
|
|
|
|
|
|
this->update(MAX (0, // needed for rewind. elapsed could be negative
|
2013-06-15 14:03:30 +08:00
|
|
|
|
MIN(1, _elapsed /
|
|
|
|
|
MAX(_duration, FLT_EPSILON) // division by 0
|
2012-05-04 16:22:50 +08:00
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-01 15:30:12 +08:00
|
|
|
|
void CCActionInterval::setAmplitudeRate(float amp)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CC_UNUSED_PARAM(amp);
|
|
|
|
|
// Abstract class needs implementation
|
|
|
|
|
CCAssert(0, "");
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-01 15:30:12 +08:00
|
|
|
|
float CCActionInterval::getAmplitudeRate(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
// Abstract class needs implementation
|
|
|
|
|
CCAssert(0, "");
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCActionInterval::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCFiniteTimeAction::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_elapsed = 0.0f;
|
|
|
|
|
_firstTick = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval* CCActionInterval::reverse(void)
|
|
|
|
|
{
|
2012-05-04 16:22:50 +08:00
|
|
|
|
CCAssert(false, "CCIntervalAction: reverse not implemented.");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Sequence
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
2012-07-23 22:49:11 +08:00
|
|
|
|
CCSequence* CCSequence::createWithTwoActions(CCFiniteTimeAction *pActionOne, CCFiniteTimeAction *pActionTwo)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCSequence *pSequence = new CCSequence();
|
2012-07-23 22:49:11 +08:00
|
|
|
|
pSequence->initWithTwoActions(pActionOne, pActionTwo);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
pSequence->autorelease();
|
|
|
|
|
|
|
|
|
|
return pSequence;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-10 12:02:24 +08:00
|
|
|
|
CCSequence* CCSequence::create(CCFiniteTimeAction *pAction1, ...)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
va_list params;
|
|
|
|
|
va_start(params, pAction1);
|
|
|
|
|
|
2012-12-10 12:02:24 +08:00
|
|
|
|
CCSequence *pRet = CCSequence::createWithVariableList(pAction1, params);
|
2012-11-15 17:16:51 +08:00
|
|
|
|
|
|
|
|
|
va_end(params);
|
|
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-10 12:02:24 +08:00
|
|
|
|
CCSequence* CCSequence::createWithVariableList(CCFiniteTimeAction *pAction1, va_list args)
|
2012-11-15 17:16:51 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCFiniteTimeAction *pNow;
|
|
|
|
|
CCFiniteTimeAction *pPrev = pAction1;
|
2012-12-10 12:02:24 +08:00
|
|
|
|
bool bOneAction = true;
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
while (pAction1)
|
|
|
|
|
{
|
2012-11-15 17:16:51 +08:00
|
|
|
|
pNow = va_arg(args, CCFiniteTimeAction*);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
if (pNow)
|
|
|
|
|
{
|
2012-07-23 22:49:11 +08:00
|
|
|
|
pPrev = createWithTwoActions(pPrev, pNow);
|
2012-12-10 12:02:24 +08:00
|
|
|
|
bOneAction = false;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-12-10 12:02:24 +08:00
|
|
|
|
// If only one action is added to CCSequence, make up a CCSequence by adding a simplest finite time action.
|
|
|
|
|
if (bOneAction)
|
|
|
|
|
{
|
|
|
|
|
pPrev = createWithTwoActions(pPrev, ExtraAction::create());
|
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-15 17:16:51 +08:00
|
|
|
|
|
2012-12-10 12:02:24 +08:00
|
|
|
|
return ((CCSequence*)pPrev);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-10 12:02:24 +08:00
|
|
|
|
CCSequence* CCSequence::create(CCArray* arrayOfActions)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2012-12-10 12:02:24 +08:00
|
|
|
|
CCSequence* pRet = NULL;
|
2012-12-10 11:10:11 +08:00
|
|
|
|
do
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2012-12-10 11:10:11 +08:00
|
|
|
|
unsigned int count = arrayOfActions->count();
|
|
|
|
|
CC_BREAK_IF(count == 0);
|
|
|
|
|
|
|
|
|
|
CCFiniteTimeAction* prev = (CCFiniteTimeAction*)arrayOfActions->objectAtIndex(0);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2012-12-10 11:10:11 +08:00
|
|
|
|
if (count > 1)
|
|
|
|
|
{
|
|
|
|
|
for (unsigned int i = 1; i < count; ++i)
|
|
|
|
|
{
|
|
|
|
|
prev = createWithTwoActions(prev, (CCFiniteTimeAction*)arrayOfActions->objectAtIndex(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-12-10 12:02:24 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// If only one action is added to CCSequence, make up a CCSequence by adding a simplest finite time action.
|
|
|
|
|
prev = createWithTwoActions(prev, ExtraAction::create());
|
|
|
|
|
}
|
|
|
|
|
pRet = (CCSequence*)prev;
|
2012-12-10 11:10:11 +08:00
|
|
|
|
}while (0);
|
|
|
|
|
return pRet;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-23 22:49:11 +08:00
|
|
|
|
bool CCSequence::initWithTwoActions(CCFiniteTimeAction *pActionOne, CCFiniteTimeAction *pActionTwo)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCAssert(pActionOne != NULL, "");
|
|
|
|
|
CCAssert(pActionTwo != NULL, "");
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
float d = pActionOne->getDuration() + pActionTwo->getDuration();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCActionInterval::initWithDuration(d);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_actions[0] = pActionOne;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
pActionOne->retain();
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_actions[1] = pActionTwo;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
pActionTwo->retain();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCSequence* CCSequence::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCSequence(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithTwoActions((CCFiniteTimeAction*)(_actions[0]->clone()),
|
|
|
|
|
(CCFiniteTimeAction*)(_actions[1]->clone())
|
2013-06-14 08:25:14 +08:00
|
|
|
|
);
|
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCSequence::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCSequence* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCSequence*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCSequence();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithTwoActions((CCFiniteTimeAction*)(_actions[0]->copy()->autorelease()),
|
|
|
|
|
(CCFiniteTimeAction*)(_actions[1]->copy()->autorelease()));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCSequence::~CCSequence(void)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CC_SAFE_RELEASE(_actions[0]);
|
|
|
|
|
CC_SAFE_RELEASE(_actions[1]);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCSequence::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_split = _actions[0]->getDuration() / _duration;
|
|
|
|
|
_last = -1;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCSequence::stop(void)
|
|
|
|
|
{
|
|
|
|
|
// Issue #1305
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if( _last != - 1)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_actions[_last]->stop();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::stop();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCSequence::update(float t)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
int found = 0;
|
2012-06-08 13:55:28 +08:00
|
|
|
|
float new_t = 0.0f;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if( t < _split ) {
|
2012-04-19 14:35:52 +08:00
|
|
|
|
// action[0]
|
|
|
|
|
found = 0;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if( _split != 0 )
|
|
|
|
|
new_t = t / _split;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
else
|
|
|
|
|
new_t = 1;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// action[1]
|
|
|
|
|
found = 1;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if ( _split == 1 )
|
2012-04-19 14:35:52 +08:00
|
|
|
|
new_t = 1;
|
|
|
|
|
else
|
2013-06-15 14:03:30 +08:00
|
|
|
|
new_t = (t-_split) / (1 - _split );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( found==1 ) {
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if( _last == -1 ) {
|
2012-04-19 14:35:52 +08:00
|
|
|
|
// action[0] was skipped, execute it.
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_actions[0]->startWithTarget(_target);
|
|
|
|
|
_actions[0]->update(1.0f);
|
|
|
|
|
_actions[0]->stop();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
|
else if( _last == 0 )
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
// switching to action 1. stop action 0.
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_actions[0]->update(1.0f);
|
|
|
|
|
_actions[0]->stop();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
|
else if(found==0 && _last==1 )
|
2013-02-27 09:38:30 +08:00
|
|
|
|
{
|
|
|
|
|
// Reverse mode ?
|
|
|
|
|
// XXX: Bug. this case doesn't contemplate when _last==-1, found=0 and in "reverse mode"
|
|
|
|
|
// since it will require a hack to know if an action is on reverse mode or not.
|
|
|
|
|
// "step" should be overriden, and the "reverseMode" value propagated to inner Sequences.
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_actions[1]->update(0);
|
|
|
|
|
_actions[1]->stop();
|
2013-02-27 09:38:30 +08:00
|
|
|
|
}
|
2012-08-22 19:46:12 +08:00
|
|
|
|
// Last action found and it is done.
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if( found == _last && _actions[found]->isDone() )
|
2012-08-22 19:46:12 +08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-15 17:16:51 +08:00
|
|
|
|
// Last action found and it is done
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if( found != _last )
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_actions[found]->startWithTarget(_target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_actions[found]->update(new_t);
|
|
|
|
|
_last = found;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
|
CCSequence* CCSequence::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
return CCSequence::createWithTwoActions(_actions[1]->reverse(), _actions[0]->reverse());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Repeat
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
|
|
CCRepeat* CCRepeat::create(CCFiniteTimeAction *pAction, unsigned int times)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCRepeat* pRepeat = new CCRepeat();
|
|
|
|
|
pRepeat->initWithAction(pAction, times);
|
|
|
|
|
pRepeat->autorelease();
|
|
|
|
|
|
|
|
|
|
return pRepeat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCRepeat::initWithAction(CCFiniteTimeAction *pAction, unsigned int times)
|
|
|
|
|
{
|
2012-06-08 13:55:28 +08:00
|
|
|
|
float d = pAction->getDuration() * times;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
if (CCActionInterval::initWithDuration(d))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_times = times;
|
|
|
|
|
_innerAction = pAction;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
pAction->retain();
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_actionInstant = dynamic_cast<CCActionInstant*>(pAction) ? true : false;
|
2012-09-17 15:02:24 +08:00
|
|
|
|
//an instant action needs to be executed one time less in the update method since it uses startWithTarget to execute the action
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_actionInstant)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_times -=1;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_total = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCRepeat* CCRepeat::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCRepeat(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithAction((CCFiniteTimeAction*)_innerAction->clone(), _times );
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCRepeat::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCRepeat* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCRepeat*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCRepeat();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithAction((CCFiniteTimeAction*)(_innerAction->copy()->autorelease()), _times);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCRepeat::~CCRepeat(void)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CC_SAFE_RELEASE(_innerAction);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCRepeat::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_total = 0;
|
|
|
|
|
_nextDt = _innerAction->getDuration()/_duration;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_innerAction->startWithTarget(pTarget);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCRepeat::stop(void)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_innerAction->stop();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCActionInterval::stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// issue #80. Instead of hooking step:, hook update: since it can be called by any
|
|
|
|
|
// container action like CCRepeat, CCSequence, CCEase, etc..
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCRepeat::update(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (dt >= _nextDt)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
while (dt > _nextDt && _total < _times)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_innerAction->update(1.0f);
|
|
|
|
|
_total++;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_innerAction->stop();
|
|
|
|
|
_innerAction->startWithTarget(_target);
|
|
|
|
|
_nextDt += _innerAction->getDuration()/_duration;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fix for issue #1288, incorrect end value of repeat
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(dt >= 1.0f && _total < _times)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_total++;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-17 15:02:24 +08:00
|
|
|
|
// don't set an instant action back or update it, it has no use because it has no duration
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (!_actionInstant)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_total == _times)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_innerAction->update(1);
|
|
|
|
|
_innerAction->stop();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// issue #390 prevent jerk, use right update
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_innerAction->update(dt - (_nextDt - _innerAction->getDuration()/_duration));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_innerAction->update(fmodf(dt * _times,1.0f));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCRepeat::isDone(void)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
return _total == _times;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
|
CCRepeat* CCRepeat::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
return CCRepeat::create(_innerAction->reverse(), _times);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// RepeatForever
|
|
|
|
|
//
|
|
|
|
|
CCRepeatForever::~CCRepeatForever()
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CC_SAFE_RELEASE(_innerAction);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
|
|
CCRepeatForever *CCRepeatForever::create(CCActionInterval *pAction)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCRepeatForever *pRet = new CCRepeatForever();
|
|
|
|
|
if (pRet && pRet->initWithAction(pAction))
|
|
|
|
|
{
|
|
|
|
|
pRet->autorelease();
|
|
|
|
|
return pRet;
|
|
|
|
|
}
|
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCRepeatForever::initWithAction(CCActionInterval *pAction)
|
|
|
|
|
{
|
|
|
|
|
CCAssert(pAction != NULL, "");
|
|
|
|
|
pAction->retain();
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_innerAction = pAction;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-06-14 08:25:14 +08:00
|
|
|
|
|
|
|
|
|
CCRepeatForever *CCRepeatForever::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCRepeatForever(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithAction((CCActionInterval*)_innerAction->clone());
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCRepeatForever::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCRepeatForever* pRet = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject) //in case of being called at sub class
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pRet = (CCRepeatForever*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pRet = new CCRepeatForever();
|
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
|
|
|
|
}
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
// win32 : use the _other's copy object.
|
|
|
|
|
pRet->initWithAction((CCActionInterval*)(_innerAction->copy()->autorelease()));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCRepeatForever::startWithTarget(CCNode* pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_innerAction->startWithTarget(pTarget);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCRepeatForever::step(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_innerAction->step(dt);
|
|
|
|
|
if (_innerAction->isDone())
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
float diff = _innerAction->getElapsed() - _innerAction->getDuration();
|
|
|
|
|
_innerAction->startWithTarget(_target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
// to prevent jerk. issue #390, 1247
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_innerAction->step(0.0f);
|
|
|
|
|
_innerAction->step(diff);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCRepeatForever::isDone()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
|
CCRepeatForever *CCRepeatForever::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-19 00:59:34 +08:00
|
|
|
|
return CCRepeatForever::create(_innerAction->reverse());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Spawn
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
2012-12-10 12:02:24 +08:00
|
|
|
|
CCSpawn* CCSpawn::create(CCFiniteTimeAction *pAction1, ...)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
va_list params;
|
|
|
|
|
va_start(params, pAction1);
|
|
|
|
|
|
2012-12-10 12:02:24 +08:00
|
|
|
|
CCSpawn *pRet = CCSpawn::createWithVariableList(pAction1, params);
|
2012-11-15 17:16:51 +08:00
|
|
|
|
|
|
|
|
|
va_end(params);
|
|
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-10 12:02:24 +08:00
|
|
|
|
CCSpawn* CCSpawn::createWithVariableList(CCFiniteTimeAction *pAction1, va_list args)
|
2012-11-15 17:16:51 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCFiniteTimeAction *pNow;
|
|
|
|
|
CCFiniteTimeAction *pPrev = pAction1;
|
2012-12-10 12:02:24 +08:00
|
|
|
|
bool bOneAction = true;
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
while (pAction1)
|
|
|
|
|
{
|
2012-11-15 17:16:51 +08:00
|
|
|
|
pNow = va_arg(args, CCFiniteTimeAction*);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
if (pNow)
|
|
|
|
|
{
|
2012-07-23 22:49:11 +08:00
|
|
|
|
pPrev = createWithTwoActions(pPrev, pNow);
|
2012-12-10 12:02:24 +08:00
|
|
|
|
bOneAction = false;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-02-27 09:38:30 +08:00
|
|
|
|
// If only one action is added to CCSpawn, make up a CCSpawn by adding a simplest finite time action.
|
|
|
|
|
if (bOneAction)
|
|
|
|
|
{
|
|
|
|
|
pPrev = createWithTwoActions(pPrev, ExtraAction::create());
|
2012-12-10 12:02:24 +08:00
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-10 12:02:24 +08:00
|
|
|
|
return ((CCSpawn*)pPrev);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-10 12:02:24 +08:00
|
|
|
|
CCSpawn* CCSpawn::create(CCArray *arrayOfActions)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-02-27 09:38:30 +08:00
|
|
|
|
CCSpawn* pRet = NULL;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
unsigned int count = arrayOfActions->count();
|
2012-12-10 12:02:24 +08:00
|
|
|
|
CC_BREAK_IF(count == 0);
|
|
|
|
|
CCFiniteTimeAction* prev = (CCFiniteTimeAction*)arrayOfActions->objectAtIndex(0);
|
2013-02-27 09:38:30 +08:00
|
|
|
|
if (count > 1)
|
2012-12-10 12:02:24 +08:00
|
|
|
|
{
|
|
|
|
|
for (unsigned int i = 1; i < arrayOfActions->count(); ++i)
|
|
|
|
|
{
|
|
|
|
|
prev = createWithTwoActions(prev, (CCFiniteTimeAction*)arrayOfActions->objectAtIndex(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-27 09:38:30 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// If only one action is added to CCSpawn, make up a CCSpawn by adding a simplest finite time action.
|
|
|
|
|
prev = createWithTwoActions(prev, ExtraAction::create());
|
|
|
|
|
}
|
|
|
|
|
pRet = (CCSpawn*)prev;
|
|
|
|
|
}while (0);
|
|
|
|
|
|
2012-12-10 12:02:24 +08:00
|
|
|
|
return pRet;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-23 22:49:11 +08:00
|
|
|
|
CCSpawn* CCSpawn::createWithTwoActions(CCFiniteTimeAction *pAction1, CCFiniteTimeAction *pAction2)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCSpawn *pSpawn = new CCSpawn();
|
2012-07-23 22:49:11 +08:00
|
|
|
|
pSpawn->initWithTwoActions(pAction1, pAction2);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
pSpawn->autorelease();
|
|
|
|
|
|
|
|
|
|
return pSpawn;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-23 22:49:11 +08:00
|
|
|
|
bool CCSpawn:: initWithTwoActions(CCFiniteTimeAction *pAction1, CCFiniteTimeAction *pAction2)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCAssert(pAction1 != NULL, "");
|
|
|
|
|
CCAssert(pAction2 != NULL, "");
|
|
|
|
|
|
|
|
|
|
bool bRet = false;
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
float d1 = pAction1->getDuration();
|
|
|
|
|
float d2 = pAction2->getDuration();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
if (CCActionInterval::initWithDuration(MAX(d1, d2)))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_one = pAction1;
|
|
|
|
|
_two = pAction2;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
if (d1 > d2)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_two = CCSequence::createWithTwoActions(pAction2, CCDelayTime::create(d1 - d2));
|
2012-08-16 14:29:27 +08:00
|
|
|
|
}
|
|
|
|
|
else if (d1 < d2)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_one = CCSequence::createWithTwoActions(pAction1, CCDelayTime::create(d2 - d1));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_one->retain();
|
|
|
|
|
_two->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
bRet = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCSpawn* CCSpawn::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCSpawn(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithTwoActions((CCFiniteTimeAction*)_one->clone(),
|
|
|
|
|
(CCFiniteTimeAction*)_two->clone());
|
2013-06-14 08:25:14 +08:00
|
|
|
|
|
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCSpawn::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCSpawn* pCopy = NULL;
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCSpawn*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCSpawn();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithTwoActions((CCFiniteTimeAction*)(_one->copy()->autorelease()),
|
|
|
|
|
(CCFiniteTimeAction*)(_two->copy()->autorelease()));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCSpawn::~CCSpawn(void)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CC_SAFE_RELEASE(_one);
|
|
|
|
|
CC_SAFE_RELEASE(_two);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCSpawn::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_one->startWithTarget(pTarget);
|
|
|
|
|
_two->startWithTarget(pTarget);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCSpawn::stop(void)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_one->stop();
|
|
|
|
|
_two->stop();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCActionInterval::stop();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCSpawn::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_one)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_one->update(time);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_two)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_two->update(time);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
|
CCSpawn* CCSpawn::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
return CCSpawn::createWithTwoActions(_one->reverse(), _two->reverse());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// RotateTo
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
2012-11-15 17:16:51 +08:00
|
|
|
|
CCRotateTo* CCRotateTo::create(float fDuration, float fDeltaAngle)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCRotateTo* pRotateTo = new CCRotateTo();
|
2012-11-15 17:16:51 +08:00
|
|
|
|
pRotateTo->initWithDuration(fDuration, fDeltaAngle);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
pRotateTo->autorelease();
|
|
|
|
|
|
|
|
|
|
return pRotateTo;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-15 17:16:51 +08:00
|
|
|
|
bool CCRotateTo::initWithDuration(float fDuration, float fDeltaAngle)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2012-11-15 17:16:51 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(fDuration))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_dstAngleX = _dstAngleY = fDeltaAngle;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-15 17:16:51 +08:00
|
|
|
|
CCRotateTo* CCRotateTo::create(float fDuration, float fDeltaAngleX, float fDeltaAngleY)
|
|
|
|
|
{
|
|
|
|
|
CCRotateTo* pRotateTo = new CCRotateTo();
|
|
|
|
|
pRotateTo->initWithDuration(fDuration, fDeltaAngleX, fDeltaAngleY);
|
|
|
|
|
pRotateTo->autorelease();
|
|
|
|
|
|
|
|
|
|
return pRotateTo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCRotateTo::initWithDuration(float fDuration, float fDeltaAngleX, float fDeltaAngleY)
|
|
|
|
|
{
|
|
|
|
|
if (CCActionInterval::initWithDuration(fDuration))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_dstAngleX = fDeltaAngleX;
|
|
|
|
|
_dstAngleY = fDeltaAngleY;
|
2012-11-15 17:16:51 +08:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCRotateTo* CCRotateTo::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCRotateTo(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithDuration(_duration, _dstAngleX, _dstAngleY);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCRotateTo::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCRotateTo* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCRotateTo*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCRotateTo();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _dstAngleX, _dstAngleY);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
//Action *copy = [[[self class] allocWithZone: zone] initWithDuration:[self duration] angle: angle];
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCRotateTo::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2012-11-15 17:16:51 +08:00
|
|
|
|
|
|
|
|
|
// Calculate X
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_startAngleX = pTarget->getRotationX();
|
|
|
|
|
if (_startAngleX > 0)
|
2013-02-27 09:38:30 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_startAngleX = fmodf(_startAngleX, 360.0f);
|
2013-02-27 09:38:30 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_startAngleX = fmodf(_startAngleX, -360.0f);
|
2012-12-26 18:59:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_diffAngleX = _dstAngleX - _startAngleX;
|
|
|
|
|
if (_diffAngleX > 180)
|
2012-11-15 17:16:51 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_diffAngleX -= 360;
|
2012-11-15 17:16:51 +08:00
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_diffAngleX < -180)
|
2012-11-15 17:16:51 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_diffAngleX += 360;
|
2012-11-15 17:16:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
//Calculate Y: It's duplicated from calculating X since the rotation wrap should be the same
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_startAngleY = _target->getRotationY();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_startAngleY > 0)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_startAngleY = fmodf(_startAngleY, 360.0f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_startAngleY = fmodf(_startAngleY, -360.0f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_diffAngleY = _dstAngleY - _startAngleY;
|
|
|
|
|
if (_diffAngleY > 180)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_diffAngleY -= 360;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_diffAngleY < -180)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_diffAngleY += 360;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCRotateTo::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_target)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_target->setRotationX(_startAngleX + _diffAngleX * time);
|
|
|
|
|
_target->setRotationY(_startAngleY + _diffAngleY * time);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCRotateTo *CCRotateTo::reverse() const
|
|
|
|
|
{
|
|
|
|
|
CCAssert(false, "RotateTo doesn't support the 'reverse' method");
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
//
|
|
|
|
|
// RotateBy
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
2012-11-15 17:16:51 +08:00
|
|
|
|
CCRotateBy* CCRotateBy::create(float fDuration, float fDeltaAngle)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCRotateBy *pRotateBy = new CCRotateBy();
|
2012-11-15 17:16:51 +08:00
|
|
|
|
pRotateBy->initWithDuration(fDuration, fDeltaAngle);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
pRotateBy->autorelease();
|
|
|
|
|
|
|
|
|
|
return pRotateBy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-15 17:16:51 +08:00
|
|
|
|
bool CCRotateBy::initWithDuration(float fDuration, float fDeltaAngle)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2012-11-15 17:16:51 +08:00
|
|
|
|
if (CCActionInterval::initWithDuration(fDuration))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_angleX = _angleY = fDeltaAngle;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-15 17:16:51 +08:00
|
|
|
|
CCRotateBy* CCRotateBy::create(float fDuration, float fDeltaAngleX, float fDeltaAngleY)
|
|
|
|
|
{
|
|
|
|
|
CCRotateBy *pRotateBy = new CCRotateBy();
|
|
|
|
|
pRotateBy->initWithDuration(fDuration, fDeltaAngleX, fDeltaAngleY);
|
|
|
|
|
pRotateBy->autorelease();
|
|
|
|
|
|
|
|
|
|
return pRotateBy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCRotateBy::initWithDuration(float fDuration, float fDeltaAngleX, float fDeltaAngleY)
|
|
|
|
|
{
|
|
|
|
|
if (CCActionInterval::initWithDuration(fDuration))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_angleX = fDeltaAngleX;
|
|
|
|
|
_angleY = fDeltaAngleY;
|
2012-11-15 17:16:51 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCRotateBy* CCRotateBy::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCRotateBy(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithDuration(_duration, _angleX, _angleY);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCRotateBy::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCRotateBy* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCRotateBy*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCRotateBy();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _angleX, _angleY);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCRotateBy::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_startAngleX = pTarget->getRotationX();
|
|
|
|
|
_startAngleY = pTarget->getRotationY();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCRotateBy::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
// XXX: shall I add % 360
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_target)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_target->setRotationX(_startAngleX + _angleX * time);
|
|
|
|
|
_target->setRotationY(_startAngleY + _angleY * time);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
|
CCRotateBy* CCRotateBy::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
return CCRotateBy::create(_duration, -_angleX, -_angleY);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
2012-12-26 18:59:31 +08:00
|
|
|
|
// MoveBy
|
2012-04-19 14:35:52 +08:00
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCMoveBy* CCMoveBy::create(float duration, const CCPoint& deltaPosition)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCMoveBy *pRet = new CCMoveBy();
|
|
|
|
|
pRet->initWithDuration(duration, deltaPosition);
|
|
|
|
|
pRet->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
return pRet;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
bool CCMoveBy::initWithDuration(float duration, const CCPoint& deltaPosition)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_positionDelta = deltaPosition;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCMoveBy* CCMoveBy::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCMoveBy(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithDuration(_duration, _positionDelta);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCObject* CCMoveBy::copyWithZone(CCZone *pZone)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCMoveBy* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCMoveBy*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
pCopy = new CCMoveBy();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _positionDelta);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
void CCMoveBy::startWithTarget(CCNode *pTarget)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_previousPosition = _startPosition = pTarget->getPosition();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
|
CCMoveBy* CCMoveBy::reverse() const
|
2012-12-26 18:59:31 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
return CCMoveBy::create(_duration, ccp( -_positionDelta.x, -_positionDelta.y));
|
2012-12-26 18:59:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CCMoveBy::update(float t)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_target)
|
2013-02-27 09:38:30 +08:00
|
|
|
|
{
|
|
|
|
|
#if CC_ENABLE_STACKABLE_ACTIONS
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCPoint currentPos = _target->getPosition();
|
|
|
|
|
CCPoint diff = ccpSub(currentPos, _previousPosition);
|
|
|
|
|
_startPosition = ccpAdd( _startPosition, diff);
|
|
|
|
|
CCPoint newPos = ccpAdd( _startPosition, ccpMult(_positionDelta, t) );
|
|
|
|
|
_target->setPosition(newPos);
|
|
|
|
|
_previousPosition = newPos;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
#else
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_target->setPosition(ccpAdd( _startPosition, ccpMult(_positionDelta, t)));
|
2013-02-27 09:38:30 +08:00
|
|
|
|
#endif // CC_ENABLE_STACKABLE_ACTIONS
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
2012-12-26 18:59:31 +08:00
|
|
|
|
// MoveTo
|
2012-04-19 14:35:52 +08:00
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCMoveTo* CCMoveTo::create(float duration, const CCPoint& position)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCMoveTo *pRet = new CCMoveTo();
|
|
|
|
|
pRet->initWithDuration(duration, position);
|
|
|
|
|
pRet->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
return pRet;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
bool CCMoveTo::initWithDuration(float duration, const CCPoint& position)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_endPosition = position;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCMoveTo* CCMoveTo::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCMoveTo(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithDuration(_duration, _endPosition);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCObject* CCMoveTo::copyWithZone(CCZone *pZone)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCMoveTo* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCMoveTo*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
pCopy = new CCMoveTo();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCMoveBy::copyWithZone(pZone);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _endPosition);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
void CCMoveTo::startWithTarget(CCNode *pTarget)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-02-27 09:38:30 +08:00
|
|
|
|
CCMoveBy::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_positionDelta = ccpSub( _endPosition, pTarget->getPosition() );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// CCSkewTo
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
CCSkewTo* CCSkewTo::create(float t, float sx, float sy)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCSkewTo *pSkewTo = new CCSkewTo();
|
|
|
|
|
if (pSkewTo)
|
|
|
|
|
{
|
|
|
|
|
if (pSkewTo->initWithDuration(t, sx, sy))
|
|
|
|
|
{
|
|
|
|
|
pSkewTo->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_DELETE(pSkewTo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pSkewTo;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
bool CCSkewTo::initWithDuration(float t, float sx, float sy)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
bool bRet = false;
|
|
|
|
|
|
|
|
|
|
if (CCActionInterval::initWithDuration(t))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_endSkewX = sx;
|
|
|
|
|
_endSkewY = sy;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
bRet = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCSkewTo* CCSkewTo::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCSkewTo(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithDuration(_duration, _endSkewX, _endSkewY);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCSkewTo::copyWithZone(CCZone* pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCSkewTo* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCSkewTo*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCSkewTo();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _endSkewX, _endSkewY);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCSkewTo::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_startSkewX = pTarget->getSkewX();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_startSkewX > 0)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_startSkewX = fmodf(_startSkewX, 180.f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_startSkewX = fmodf(_startSkewX, -180.f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_deltaX = _endSkewX - _startSkewX;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_deltaX > 180)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_deltaX -= 360;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_deltaX < -180)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_deltaX += 360;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_startSkewY = pTarget->getSkewY();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_startSkewY > 0)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_startSkewY = fmodf(_startSkewY, 360.f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_startSkewY = fmodf(_startSkewY, -360.f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_deltaY = _endSkewY - _startSkewY;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_deltaY > 180)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_deltaY -= 360;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_deltaY < -180)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_deltaY += 360;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCSkewTo::update(float t)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_target->setSkewX(_startSkewX + _deltaX * t);
|
|
|
|
|
_target->setSkewY(_startSkewY + _deltaY * t);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCSkewTo::CCSkewTo()
|
2013-06-15 14:03:30 +08:00
|
|
|
|
: _skewX(0.0)
|
|
|
|
|
, _skewY(0.0)
|
|
|
|
|
, _startSkewX(0.0)
|
|
|
|
|
, _startSkewY(0.0)
|
|
|
|
|
, _endSkewX(0.0)
|
|
|
|
|
, _endSkewY(0.0)
|
|
|
|
|
, _deltaX(0.0)
|
|
|
|
|
, _deltaY(0.0)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// CCSkewBy
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
CCSkewBy* CCSkewBy::create(float t, float sx, float sy)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCSkewBy *pSkewBy = new CCSkewBy();
|
|
|
|
|
if (pSkewBy)
|
|
|
|
|
{
|
|
|
|
|
if (pSkewBy->initWithDuration(t, sx, sy))
|
|
|
|
|
{
|
|
|
|
|
pSkewBy->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_DELETE(pSkewBy);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pSkewBy;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCSkewBy * CCSkewBy::clone() const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCSkewBy(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
|
a->initWithDuration(_duration, _skewX, _skewY);
|
2013-06-16 10:44:39 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
bool CCSkewBy::initWithDuration(float t, float deltaSkewX, float deltaSkewY)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
bool bRet = false;
|
|
|
|
|
|
|
|
|
|
if (CCSkewTo::initWithDuration(t, deltaSkewX, deltaSkewY))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_skewX = deltaSkewX;
|
|
|
|
|
_skewY = deltaSkewY;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
bRet = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCSkewBy::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCSkewTo::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_deltaX = _skewX;
|
|
|
|
|
_deltaY = _skewY;
|
|
|
|
|
_endSkewX = _startSkewX + _deltaX;
|
|
|
|
|
_endSkewY = _startSkewY + _deltaY;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
|
CCSkewBy* CCSkewBy::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-19 00:59:34 +08:00
|
|
|
|
return CCSkewBy::create(_duration, -_skewX, -_skewY);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// JumpBy
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
|
|
CCJumpBy* CCJumpBy::create(float duration, const CCPoint& position, float height, unsigned int jumps)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCJumpBy *pJumpBy = new CCJumpBy();
|
|
|
|
|
pJumpBy->initWithDuration(duration, position, height, jumps);
|
|
|
|
|
pJumpBy->autorelease();
|
|
|
|
|
|
|
|
|
|
return pJumpBy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
bool CCJumpBy::initWithDuration(float duration, const CCPoint& position, float height, unsigned int jumps)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_delta = position;
|
|
|
|
|
_height = height;
|
|
|
|
|
_jumps = jumps;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCJumpBy* CCJumpBy::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCJumpBy(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithDuration(_duration, _delta, _height, _jumps);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCJumpBy::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCJumpBy* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCJumpBy*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCJumpBy();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _delta, _height, _jumps);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCJumpBy::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_previousPos = _startPosition = pTarget->getPosition();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
void CCJumpBy::update(float t)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
// parabolic jump (since v0.8.2)
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_target)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
float frac = fmodf( t * _jumps, 1.0f );
|
|
|
|
|
float y = _height * 4 * frac * (1 - frac);
|
|
|
|
|
y += _delta.y * t;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
float x = _delta.x * t;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
#if CC_ENABLE_STACKABLE_ACTIONS
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCPoint currentPos = _target->getPosition();
|
2013-02-27 09:38:30 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCPoint diff = ccpSub( currentPos, _previousPos );
|
|
|
|
|
_startPosition = ccpAdd( diff, _startPosition);
|
2013-02-27 09:38:30 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCPoint newPos = ccpAdd( _startPosition, ccp(x,y));
|
|
|
|
|
_target->setPosition(newPos);
|
2013-02-27 09:38:30 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_previousPos = newPos;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
#else
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_target->setPosition(ccpAdd( _startPosition, ccp(x,y)));
|
2013-02-27 09:38:30 +08:00
|
|
|
|
#endif // !CC_ENABLE_STACKABLE_ACTIONS
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 09:54:34 +08:00
|
|
|
|
CCJumpBy* CCJumpBy::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
return CCJumpBy::create(_duration, ccp(-_delta.x, -_delta.y),
|
|
|
|
|
_height, _jumps);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// JumpTo
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
|
|
CCJumpTo* CCJumpTo::create(float duration, const CCPoint& position, float height, int jumps)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCJumpTo *pJumpTo = new CCJumpTo();
|
|
|
|
|
pJumpTo->initWithDuration(duration, position, height, jumps);
|
|
|
|
|
pJumpTo->autorelease();
|
|
|
|
|
|
|
|
|
|
return pJumpTo;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCJumpTo* CCJumpTo::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCJumpTo(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithDuration(_duration, _delta, _height, _jumps);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCJumpTo::copyWithZone(CCZone* pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCJumpTo* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCJumpTo*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCJumpTo();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCJumpBy::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _delta, _height, _jumps);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCJumpTo::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCJumpBy::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_delta = ccp(_delta.x - _startPosition.x, _delta.y - _startPosition.y);
|
2012-04-19 14:35:52 +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
|
2012-06-08 13:55:28 +08:00
|
|
|
|
static inline float bezierat( float a, float b, float c, float d, float t )
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
return (powf(1-t,3) * a +
|
|
|
|
|
3*t*(powf(1-t,2))*b +
|
|
|
|
|
3*powf(t,2)*(1-t)*c +
|
|
|
|
|
powf(t,3)*d );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// BezierBy
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
|
|
CCBezierBy* CCBezierBy::create(float t, const ccBezierConfig& c)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCBezierBy *pBezierBy = new CCBezierBy();
|
|
|
|
|
pBezierBy->initWithDuration(t, c);
|
|
|
|
|
pBezierBy->autorelease();
|
|
|
|
|
|
|
|
|
|
return pBezierBy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
bool CCBezierBy::initWithDuration(float t, const ccBezierConfig& c)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
if (CCActionInterval::initWithDuration(t))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_config = c;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCBezierBy::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_previousPosition = _startPosition = pTarget->getPosition();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCBezierBy* CCBezierBy::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCBezierBy(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithDuration(_duration, _config);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCBezierBy::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCBezierBy* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCBezierBy*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCBezierBy();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _config);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCBezierBy::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_target)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
float xa = 0;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
float xb = _config.controlPoint_1.x;
|
|
|
|
|
float xc = _config.controlPoint_2.x;
|
|
|
|
|
float xd = _config.endPosition.x;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
float ya = 0;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
float yb = _config.controlPoint_1.y;
|
|
|
|
|
float yc = _config.controlPoint_2.y;
|
|
|
|
|
float yd = _config.endPosition.y;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
float x = bezierat(xa, xb, xc, xd, time);
|
|
|
|
|
float y = bezierat(ya, yb, yc, yd, time);
|
2013-02-27 09:38:30 +08:00
|
|
|
|
|
|
|
|
|
#if CC_ENABLE_STACKABLE_ACTIONS
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCPoint currentPos = _target->getPosition();
|
|
|
|
|
CCPoint diff = ccpSub(currentPos, _previousPosition);
|
|
|
|
|
_startPosition = ccpAdd( _startPosition, diff);
|
2013-02-27 09:38:30 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCPoint newPos = ccpAdd( _startPosition, ccp(x,y));
|
|
|
|
|
_target->setPosition(newPos);
|
2013-02-27 09:38:30 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_previousPosition = newPos;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
#else
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_target->setPosition(ccpAdd( _startPosition, ccp(x,y)));
|
2013-02-27 09:38:30 +08:00
|
|
|
|
#endif // !CC_ENABLE_STACKABLE_ACTIONS
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCBezierBy* CCBezierBy::reverse(void) const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
ccBezierConfig r;
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
r.endPosition = ccpNeg(_config.endPosition);
|
|
|
|
|
r.controlPoint_1 = ccpAdd(_config.controlPoint_2, ccpNeg(_config.endPosition));
|
|
|
|
|
r.controlPoint_2 = ccpAdd(_config.controlPoint_1, ccpNeg(_config.endPosition));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCBezierBy *pAction = CCBezierBy::create(_duration, r);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return pAction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// BezierTo
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
|
|
CCBezierTo* CCBezierTo::create(float t, const ccBezierConfig& c)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCBezierTo *pBezierTo = new CCBezierTo();
|
|
|
|
|
pBezierTo->initWithDuration(t, c);
|
|
|
|
|
pBezierTo->autorelease();
|
|
|
|
|
|
|
|
|
|
return pBezierTo;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-15 17:16:51 +08:00
|
|
|
|
bool CCBezierTo::initWithDuration(float t, const ccBezierConfig &c)
|
|
|
|
|
{
|
|
|
|
|
bool bRet = false;
|
|
|
|
|
|
|
|
|
|
if (CCActionInterval::initWithDuration(t))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_toConfig = c;
|
2012-11-15 17:16:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCBezierTo* CCBezierTo::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCBezierTo(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithDuration(_duration, _config);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCBezierTo::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCBezierBy* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCBezierTo*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCBezierTo();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCBezierBy::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _config);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCBezierTo::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCBezierBy::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_config.controlPoint_1 = ccpSub(_toConfig.controlPoint_1, _startPosition);
|
|
|
|
|
_config.controlPoint_2 = ccpSub(_toConfig.controlPoint_2, _startPosition);
|
|
|
|
|
_config.endPosition = ccpSub(_toConfig.endPosition, _startPosition);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCBezierTo* CCBezierTo::reverse() const
|
|
|
|
|
{
|
|
|
|
|
CCAssert(false, "CCBezierTo doesn't support the 'reverse' method");
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
//
|
|
|
|
|
// ScaleTo
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
CCScaleTo* CCScaleTo::create(float duration, float s)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCScaleTo *pScaleTo = new CCScaleTo();
|
|
|
|
|
pScaleTo->initWithDuration(duration, s);
|
|
|
|
|
pScaleTo->autorelease();
|
|
|
|
|
|
|
|
|
|
return pScaleTo;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
bool CCScaleTo::initWithDuration(float duration, float s)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_endScaleX = s;
|
|
|
|
|
_endScaleY = s;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
|
CCScaleTo* CCScaleTo::create(float duration, float sx, float sy)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCScaleTo *pScaleTo = new CCScaleTo();
|
|
|
|
|
pScaleTo->initWithDuration(duration, sx, sy);
|
|
|
|
|
pScaleTo->autorelease();
|
|
|
|
|
|
|
|
|
|
return pScaleTo;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
bool CCScaleTo::initWithDuration(float duration, float sx, float sy)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_endScaleX = sx;
|
|
|
|
|
_endScaleY = sy;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCScaleTo* CCScaleTo::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCScaleTo(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithDuration(_duration, _endScaleX, _endScaleY);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCScaleTo::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCScaleTo* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCScaleTo*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCScaleTo();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _endScaleX, _endScaleY);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCScaleTo::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_startScaleX = pTarget->getScaleX();
|
|
|
|
|
_startScaleY = pTarget->getScaleY();
|
|
|
|
|
_deltaX = _endScaleX - _startScaleX;
|
|
|
|
|
_deltaY = _endScaleY - _startScaleY;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCScaleTo::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_target)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_target->setScaleX(_startScaleX + _deltaX * time);
|
|
|
|
|
_target->setScaleY(_startScaleY + _deltaY * time);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// ScaleBy
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
|
|
CCScaleBy* CCScaleBy::create(float duration, float s)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCScaleBy *pScaleBy = new CCScaleBy();
|
|
|
|
|
pScaleBy->initWithDuration(duration, s);
|
|
|
|
|
pScaleBy->autorelease();
|
|
|
|
|
|
|
|
|
|
return pScaleBy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
|
CCScaleBy* CCScaleBy::create(float duration, float sx, float sy)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCScaleBy *pScaleBy = new CCScaleBy();
|
|
|
|
|
pScaleBy->initWithDuration(duration, sx, sy);
|
|
|
|
|
pScaleBy->autorelease();
|
|
|
|
|
|
|
|
|
|
return pScaleBy;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCScaleBy* CCScaleBy::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCScaleBy(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithDuration(_duration, _endScaleX, _endScaleY);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCScaleBy::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCScaleTo* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCScaleBy*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCScaleBy();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCScaleTo::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _endScaleX, _endScaleY);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCScaleBy::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCScaleTo::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_deltaX = _startScaleX * _endScaleX - _startScaleX;
|
|
|
|
|
_deltaY = _startScaleY * _endScaleY - _startScaleY;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 09:54:34 +08:00
|
|
|
|
CCScaleBy* CCScaleBy::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
return CCScaleBy::create(_duration, 1 / _endScaleX, 1 / _endScaleY);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Blink
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
|
|
CCBlink* CCBlink::create(float duration, unsigned int uBlinks)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCBlink *pBlink = new CCBlink();
|
|
|
|
|
pBlink->initWithDuration(duration, uBlinks);
|
|
|
|
|
pBlink->autorelease();
|
|
|
|
|
|
|
|
|
|
return pBlink;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
bool CCBlink::initWithDuration(float duration, unsigned int uBlinks)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_times = uBlinks;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-15 17:16:51 +08:00
|
|
|
|
void CCBlink::stop()
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_target->setVisible(_originalState);
|
2012-11-15 17:16:51 +08:00
|
|
|
|
CCActionInterval::stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCBlink::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_originalState = pTarget->isVisible();
|
2012-11-15 17:16:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCBlink* CCBlink::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCBlink(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithDuration(_duration, (unsigned int)_times);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCBlink::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCBlink* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCBlink*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCBlink();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, (unsigned int)_times);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCBlink::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_target && ! isDone())
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
float slice = 1.0f / _times;
|
2012-06-08 13:55:28 +08:00
|
|
|
|
float m = fmodf(time, slice);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_target->setVisible(m > slice / 2 ? true : false);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
|
CCBlink* CCBlink::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
return CCBlink::create(_duration, _times);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// FadeIn
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
|
|
CCFadeIn* CCFadeIn::create(float d)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCFadeIn* pAction = new CCFadeIn();
|
|
|
|
|
|
|
|
|
|
pAction->initWithDuration(d);
|
2012-06-14 15:13:16 +08:00
|
|
|
|
pAction->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
return pAction;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCFadeIn* CCFadeIn::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCFadeIn(*this);
|
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCFadeIn::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCFadeIn* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCFadeIn*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCFadeIn();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCFadeIn::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = dynamic_cast<CCRGBAProtocol*>(_target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
|
|
|
|
pRGBAProtocol->setOpacity((GLubyte)(255 * time));
|
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
|
/*_target->setOpacity((GLubyte)(255 * time));*/
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 09:54:34 +08:00
|
|
|
|
CCActionInterval* CCFadeIn::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
return CCFadeOut::create(_duration);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// FadeOut
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
|
|
CCFadeOut* CCFadeOut::create(float d)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCFadeOut* pAction = new CCFadeOut();
|
|
|
|
|
|
|
|
|
|
pAction->initWithDuration(d);
|
2012-06-14 15:13:16 +08:00
|
|
|
|
pAction->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
return pAction;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCFadeOut* CCFadeOut::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCFadeOut(*this);
|
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCFadeOut::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCFadeOut* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCFadeOut*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCFadeOut();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCFadeOut::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = dynamic_cast<CCRGBAProtocol*>(_target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
|
|
|
|
pRGBAProtocol->setOpacity(GLubyte(255 * (1 - time)));
|
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
|
/*_target->setOpacity(GLubyte(255 * (1 - time)));*/
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 09:54:34 +08:00
|
|
|
|
CCActionInterval* CCFadeOut::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
return CCFadeIn::create(_duration);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// FadeTo
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
|
|
CCFadeTo* CCFadeTo::create(float duration, GLubyte opacity)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCFadeTo *pFadeTo = new CCFadeTo();
|
|
|
|
|
pFadeTo->initWithDuration(duration, opacity);
|
|
|
|
|
pFadeTo->autorelease();
|
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
|
return pFadeTo;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
bool CCFadeTo::initWithDuration(float duration, GLubyte opacity)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_toOpacity = opacity;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCFadeTo* CCFadeTo::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCFadeTo(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithDuration(_duration, _toOpacity);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCFadeTo::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCFadeTo* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCFadeTo*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCFadeTo();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _toOpacity);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCFadeTo::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
|
|
|
|
|
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = dynamic_cast<CCRGBAProtocol*>(pTarget);
|
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_fromOpacity = pRGBAProtocol->getOpacity();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
|
/*_fromOpacity = pTarget->getOpacity();*/
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCFadeTo::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = dynamic_cast<CCRGBAProtocol*>(_target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pRGBAProtocol->setOpacity((GLubyte)(_fromOpacity + (_toOpacity - _fromOpacity) * time));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
|
/*_target->setOpacity((GLubyte)(_fromOpacity + (_toOpacity - _fromOpacity) * time));*/
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// TintTo
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
CCTintTo* CCTintTo::create(float duration, GLubyte red, GLubyte green, GLubyte blue)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCTintTo *pTintTo = new CCTintTo();
|
|
|
|
|
pTintTo->initWithDuration(duration, red, green, blue);
|
|
|
|
|
pTintTo->autorelease();
|
|
|
|
|
|
|
|
|
|
return pTintTo;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
bool CCTintTo::initWithDuration(float duration, GLubyte red, GLubyte green, GLubyte blue)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_to = ccc3(red, green, blue);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCTintTo* CCTintTo::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCTintTo(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithDuration(_duration, _to.r, _to.g, _to.b);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCTintTo::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCTintTo* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCTintTo*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCTintTo();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _to.r, _to.g, _to.b);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCTintTo::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = dynamic_cast<CCRGBAProtocol*>(_target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_from = pRGBAProtocol->getColor();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
|
/*_from = pTarget->getColor();*/
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCTintTo::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = dynamic_cast<CCRGBAProtocol*>(_target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pRGBAProtocol->setColor(ccc3(GLubyte(_from.r + (_to.r - _from.r) * time),
|
|
|
|
|
(GLbyte)(_from.g + (_to.g - _from.g) * time),
|
|
|
|
|
(GLbyte)(_from.b + (_to.b - _from.b) * time)));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// TintBy
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
|
|
CCTintBy* CCTintBy::create(float duration, GLshort deltaRed, GLshort deltaGreen, GLshort deltaBlue)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCTintBy *pTintBy = new CCTintBy();
|
|
|
|
|
pTintBy->initWithDuration(duration, deltaRed, deltaGreen, deltaBlue);
|
|
|
|
|
pTintBy->autorelease();
|
|
|
|
|
|
|
|
|
|
return pTintBy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
bool CCTintBy::initWithDuration(float duration, GLshort deltaRed, GLshort deltaGreen, GLshort deltaBlue)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_deltaR = deltaRed;
|
|
|
|
|
_deltaG = deltaGreen;
|
|
|
|
|
_deltaB = deltaBlue;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCTintBy* CCTintBy::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCTintBy(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithDuration(_duration, (GLubyte)_deltaR, (GLubyte)_deltaG, (GLubyte)_deltaB);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCTintBy::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCTintBy* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCTintBy*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCTintBy();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, (GLubyte)_deltaR, (GLubyte)_deltaG, (GLubyte)_deltaB);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCTintBy::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
|
|
|
|
|
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = dynamic_cast<CCRGBAProtocol*>(pTarget);
|
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
|
|
|
|
ccColor3B color = pRGBAProtocol->getColor();
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_fromR = color.r;
|
|
|
|
|
_fromG = color.g;
|
|
|
|
|
_fromB = color.b;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCTintBy::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCRGBAProtocol *pRGBAProtocol = dynamic_cast<CCRGBAProtocol*>(_target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
if (pRGBAProtocol)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pRGBAProtocol->setColor(ccc3((GLubyte)(_fromR + _deltaR * time),
|
|
|
|
|
(GLubyte)(_fromG + _deltaG * time),
|
|
|
|
|
(GLubyte)(_fromB + _deltaB * time)));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 09:54:34 +08:00
|
|
|
|
CCTintBy* CCTintBy::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
return CCTintBy::create(_duration, -_deltaR, -_deltaG, -_deltaB);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// DelayTime
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
CCDelayTime* CCDelayTime::create(float d)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCDelayTime* pAction = new CCDelayTime();
|
|
|
|
|
|
|
|
|
|
pAction->initWithDuration(d);
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
|
|
|
|
|
return pAction;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCDelayTime* CCDelayTime::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCDelayTime(*this);
|
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCDelayTime::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCDelayTime* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCDelayTime*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCDelayTime();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCDelayTime::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CC_UNUSED_PARAM(time);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 09:54:34 +08:00
|
|
|
|
CCDelayTime* CCDelayTime::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
return CCDelayTime::create(_duration);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// ReverseTime
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
|
|
CCReverseTime* CCReverseTime::create(CCFiniteTimeAction *pAction)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
// casting to prevent warnings
|
|
|
|
|
CCReverseTime *pReverseTime = new CCReverseTime();
|
2013-06-16 09:54:34 +08:00
|
|
|
|
pReverseTime->initWithAction( pAction->clone() );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
pReverseTime->autorelease();
|
|
|
|
|
|
|
|
|
|
return pReverseTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCReverseTime::initWithAction(CCFiniteTimeAction *pAction)
|
|
|
|
|
{
|
|
|
|
|
CCAssert(pAction != NULL, "");
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCAssert(pAction != _other, "");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
if (CCActionInterval::initWithDuration(pAction->getDuration()))
|
|
|
|
|
{
|
|
|
|
|
// Don't leak if action is reused
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CC_SAFE_RELEASE(_other);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_other = pAction;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
pAction->retain();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCReverseTime* CCReverseTime::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCReverseTime(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
|
a->initWithAction( _other->clone() );
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCReverseTime::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCReverseTime* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCReverseTime*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCReverseTime();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithAction((CCFiniteTimeAction*)(_other->copy()->autorelease()));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCReverseTime::CCReverseTime() : _other(NULL)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCReverseTime::~CCReverseTime(void)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CC_SAFE_RELEASE(_other);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCReverseTime::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_other->startWithTarget(pTarget);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCReverseTime::stop(void)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_other->stop();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCActionInterval::stop();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCReverseTime::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_other)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_other->update(1 - time);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 09:54:34 +08:00
|
|
|
|
CCFiniteTimeAction* CCReverseTime::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-19 00:59:34 +08:00
|
|
|
|
return _other->clone();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Animate
|
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
CCAnimate* CCAnimate::create(CCAnimation *pAnimation)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCAnimate *pAnimate = new CCAnimate();
|
|
|
|
|
pAnimate->initWithAnimation(pAnimation);
|
|
|
|
|
pAnimate->autorelease();
|
|
|
|
|
|
|
|
|
|
return pAnimate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CCAnimate::initWithAnimation(CCAnimation *pAnimation)
|
|
|
|
|
{
|
|
|
|
|
CCAssert( pAnimation!=NULL, "Animate: argument Animation must be non-NULL");
|
|
|
|
|
|
|
|
|
|
float singleDuration = pAnimation->getDuration();
|
|
|
|
|
|
|
|
|
|
if ( CCActionInterval::initWithDuration(singleDuration * pAnimation->getLoops() ) )
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_nextFrame = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
setAnimation(pAnimation);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_origFrame = NULL;
|
|
|
|
|
_executedLoops = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_splitTimes->reserve(pAnimation->getFrames()->count());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
float accumUnitsOfTime = 0;
|
|
|
|
|
float newUnitOfTimeValue = singleDuration / pAnimation->getTotalDelayUnits();
|
|
|
|
|
|
|
|
|
|
CCArray* pFrames = pAnimation->getFrames();
|
|
|
|
|
CCARRAY_VERIFY_TYPE(pFrames, CCAnimationFrame*);
|
|
|
|
|
|
|
|
|
|
CCObject* pObj = NULL;
|
|
|
|
|
CCARRAY_FOREACH(pFrames, pObj)
|
|
|
|
|
{
|
|
|
|
|
CCAnimationFrame* frame = (CCAnimationFrame*)pObj;
|
|
|
|
|
float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
|
|
|
|
|
accumUnitsOfTime += frame->getDelayUnits();
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_splitTimes->push_back(value);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCAnimate* CCAnimate::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCAnimate(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
a->initWithAnimation((CCAnimation*)_animation->copy()->autorelease());
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCAnimate::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCAnimate* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCAnimate*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCAnimate();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithAnimation((CCAnimation*)_animation->copy()->autorelease());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCAnimate::CCAnimate()
|
2013-06-15 14:03:30 +08:00
|
|
|
|
: _animation(NULL)
|
|
|
|
|
, _splitTimes(new std::vector<float>)
|
|
|
|
|
, _nextFrame(0)
|
|
|
|
|
, _origFrame(NULL)
|
|
|
|
|
, _executedLoops(0)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCAnimate::~CCAnimate()
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CC_SAFE_RELEASE(_animation);
|
|
|
|
|
CC_SAFE_RELEASE(_origFrame);
|
|
|
|
|
CC_SAFE_DELETE(_splitTimes);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCAnimate::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
|
|
|
|
CCSprite *pSprite = (CCSprite*)(pTarget);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CC_SAFE_RELEASE(_origFrame);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_animation->getRestoreOriginalFrame())
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_origFrame = pSprite->displayFrame();
|
|
|
|
|
_origFrame->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_nextFrame = 0;
|
|
|
|
|
_executedLoops = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCAnimate::stop(void)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_animation->getRestoreOriginalFrame() && _target)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
((CCSprite*)(_target))->setDisplayFrame(_origFrame);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCActionInterval::stop();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCAnimate::update(float t)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
// if t==1, ignore. Animation should finish with t==1
|
|
|
|
|
if( t < 1.0f ) {
|
2013-06-15 14:03:30 +08:00
|
|
|
|
t *= _animation->getLoops();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
// new loop? If so, reset frame counter
|
|
|
|
|
unsigned int loopNumber = (unsigned int)t;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if( loopNumber > _executedLoops ) {
|
|
|
|
|
_nextFrame = 0;
|
|
|
|
|
_executedLoops++;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// new t for animations
|
|
|
|
|
t = fmodf(t, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCArray* frames = _animation->getFrames();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
unsigned int numberOfFrames = frames->count();
|
|
|
|
|
CCSpriteFrame *frameToDisplay = NULL;
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for( unsigned int i=_nextFrame; i < numberOfFrames; i++ ) {
|
|
|
|
|
float splitTime = _splitTimes->at(i);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
if( splitTime <= t ) {
|
|
|
|
|
CCAnimationFrame* frame = (CCAnimationFrame*)frames->objectAtIndex(i);
|
|
|
|
|
frameToDisplay = frame->getSpriteFrame();
|
2013-06-15 14:03:30 +08:00
|
|
|
|
((CCSprite*)_target)->setDisplayFrame(frameToDisplay);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CCDictionary* dict = frame->getUserInfo();
|
|
|
|
|
if( dict )
|
|
|
|
|
{
|
|
|
|
|
//TODO: [[NSNotificationCenter defaultCenter] postNotificationName:CCAnimationFrameDisplayedNotification object:target_ userInfo:dict];
|
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_nextFrame = i+1;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
}
|
|
|
|
|
// Issue 1438. Could be more than one frame per tick, due to low frame rate or frame delta < 1/FPS
|
2012-12-26 18:59:31 +08:00
|
|
|
|
else {
|
2012-04-19 14:35:52 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
|
CCAnimate* CCAnimate::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCArray* pOldArray = _animation->getFrames();
|
2012-07-23 22:49:11 +08:00
|
|
|
|
CCArray* pNewArray = CCArray::createWithCapacity(pOldArray->count());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CCARRAY_VERIFY_TYPE(pOldArray, CCAnimationFrame*);
|
|
|
|
|
|
|
|
|
|
if (pOldArray->count() > 0)
|
|
|
|
|
{
|
|
|
|
|
CCObject* pObj = NULL;
|
|
|
|
|
CCARRAY_FOREACH_REVERSE(pOldArray, pObj)
|
|
|
|
|
{
|
|
|
|
|
CCAnimationFrame* pElement = (CCAnimationFrame*)pObj;
|
|
|
|
|
if (! pElement)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pNewArray->addObject((CCAnimationFrame*)(pElement->copy()->autorelease()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCAnimation *newAnim = CCAnimation::create(pNewArray, _animation->getDelayPerUnit(), _animation->getLoops());
|
|
|
|
|
newAnim->setRestoreOriginalFrame(_animation->getRestoreOriginalFrame());
|
2012-06-14 15:13:16 +08:00
|
|
|
|
return create(newAnim);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CCTargetedAction
|
|
|
|
|
|
|
|
|
|
CCTargetedAction::CCTargetedAction()
|
2013-06-15 14:03:30 +08:00
|
|
|
|
: _forcedTarget(NULL)
|
|
|
|
|
, _action(NULL)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCTargetedAction::~CCTargetedAction()
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CC_SAFE_RELEASE(_forcedTarget);
|
|
|
|
|
CC_SAFE_RELEASE(_action);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
|
CCTargetedAction* CCTargetedAction::create(CCNode* pTarget, CCFiniteTimeAction* pAction)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
CCTargetedAction* p = new CCTargetedAction();
|
|
|
|
|
p->initWithTarget(pTarget, pAction);
|
|
|
|
|
p->autorelease();
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
bool CCTargetedAction::initWithTarget(CCNode* pTarget, CCFiniteTimeAction* pAction)
|
|
|
|
|
{
|
|
|
|
|
if(CCActionInterval::initWithDuration(pAction->getDuration()))
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_RETAIN(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_forcedTarget = pTarget;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CC_SAFE_RETAIN(pAction);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_action = pAction;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
|
CCTargetedAction* CCTargetedAction::clone(void) const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCTargetedAction(*this);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
// win32 : use the _other's copy object.
|
|
|
|
|
a->initWithTarget(_forcedTarget, (CCFiniteTimeAction*)_action->clone());
|
2013-06-14 08:25:14 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCTargetedAction* CCTargetedAction::reverse(void) const
|
|
|
|
|
{
|
|
|
|
|
// no reverse for this action, just clone it
|
|
|
|
|
return this->clone();
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCObject* CCTargetedAction::copyWithZone(CCZone* pZone)
|
|
|
|
|
{
|
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCTargetedAction* pRet = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject) //in case of being called at sub class
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pRet = (CCTargetedAction*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pRet = new CCTargetedAction();
|
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
|
|
|
|
}
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
// win32 : use the _other's copy object.
|
|
|
|
|
pRet->initWithTarget(_forcedTarget, (CCFiniteTimeAction*)_action->copy()->autorelease());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCTargetedAction::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
2012-11-15 17:16:51 +08:00
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_action->startWithTarget(_forcedTarget);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CCTargetedAction::stop(void)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_action->stop();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCTargetedAction::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_action->update(time);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_CC_END
|