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"
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "CCStdC.h"
|
|
|
|
#include "CCActionInstant.h"
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// Extra action for making a Sequence or Spawn when only adding one action to it.
|
|
|
|
class ExtraAction : public FiniteTimeAction
|
2012-12-10 12:02:24 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static ExtraAction* create();
|
2013-06-14 08:25:14 +08:00
|
|
|
virtual ExtraAction* clone() const;
|
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
|
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new ExtraAction();
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
2012-12-10 12:02:24 +08:00
|
|
|
|
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
|
|
|
|
//
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool ActionInterval::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;
|
|
|
|
}
|
|
|
|
|
2013-07-07 13:01:21 +08:00
|
|
|
bool ActionInterval::isDone(void) const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _elapsed >= _duration;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ActionInterval::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
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ActionInterval::setAmplitudeRate(float amp)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CC_UNUSED_PARAM(amp);
|
|
|
|
// Abstract class needs implementation
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(0, "");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
float ActionInterval::getAmplitudeRate(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// Abstract class needs implementation
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(0, "");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void ActionInterval::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
FiniteTimeAction::startWithTarget(target);
|
2013-06-15 14:03:30 +08:00
|
|
|
_elapsed = 0.0f;
|
|
|
|
_firstTick = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Sequence
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Sequence* Sequence::createWithTwoActions(FiniteTimeAction *pActionOne, FiniteTimeAction *pActionTwo)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Sequence *pSequence = new Sequence();
|
2012-07-23 22:49:11 +08:00
|
|
|
pSequence->initWithTwoActions(pActionOne, pActionTwo);
|
2012-04-19 14:35:52 +08:00
|
|
|
pSequence->autorelease();
|
|
|
|
|
|
|
|
return pSequence;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Sequence* Sequence::create(FiniteTimeAction *pAction1, ...)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
va_list params;
|
|
|
|
va_start(params, pAction1);
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Sequence *pRet = Sequence::createWithVariableList(pAction1, params);
|
2012-11-15 17:16:51 +08:00
|
|
|
|
|
|
|
va_end(params);
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Sequence* Sequence::createWithVariableList(FiniteTimeAction *pAction1, va_list args)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
FiniteTimeAction *pNow;
|
|
|
|
FiniteTimeAction *pPrev = pAction1;
|
2012-12-10 12:02:24 +08:00
|
|
|
bool bOneAction = true;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
while (pAction1)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
pNow = va_arg(args, FiniteTimeAction*);
|
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-06-20 14:13:12 +08:00
|
|
|
// If only one action is added to Sequence, make up a Sequence by adding a simplest finite time action.
|
2012-12-10 12:02:24 +08:00
|
|
|
if (bOneAction)
|
|
|
|
{
|
|
|
|
pPrev = createWithTwoActions(pPrev, ExtraAction::create());
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-15 17:16:51 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
return ((Sequence*)pPrev);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Sequence* Sequence::create(Array* arrayOfActions)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Sequence* 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);
|
|
|
|
|
2013-07-09 05:38:14 +08:00
|
|
|
FiniteTimeAction* prev = static_cast<FiniteTimeAction*>( 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)
|
|
|
|
{
|
2013-07-09 05:38:14 +08:00
|
|
|
prev = createWithTwoActions(prev, static_cast<FiniteTimeAction*>( arrayOfActions->objectAtIndex(i)) );
|
2012-12-10 11:10:11 +08:00
|
|
|
}
|
|
|
|
}
|
2012-12-10 12:02:24 +08:00
|
|
|
else
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
// If only one action is added to Sequence, make up a Sequence by adding a simplest finite time action.
|
2012-12-10 12:02:24 +08:00
|
|
|
prev = createWithTwoActions(prev, ExtraAction::create());
|
|
|
|
}
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = (Sequence*)prev;
|
2012-12-10 11:10:11 +08:00
|
|
|
}while (0);
|
|
|
|
return pRet;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool Sequence::initWithTwoActions(FiniteTimeAction *pActionOne, FiniteTimeAction *pActionTwo)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(pActionOne != NULL, "");
|
|
|
|
CCASSERT(pActionTwo != NULL, "");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
float d = pActionOne->getDuration() + pActionTwo->getDuration();
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInterval::initWithDuration(d);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
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-20 14:13:12 +08:00
|
|
|
Sequence* Sequence::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new Sequence();
|
2013-07-08 23:05:47 +08:00
|
|
|
a->initWithTwoActions(_actions[0]->clone(), _actions[1]->clone() );
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Sequence::~Sequence(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void Sequence::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
2013-06-15 14:03:30 +08:00
|
|
|
_split = _actions[0]->getDuration() / _duration;
|
|
|
|
_last = -1;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Sequence::stop(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInterval::stop();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Sequence::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-20 14:13:12 +08:00
|
|
|
Sequence* Sequence::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return Sequence::createWithTwoActions(_actions[1]->reverse(), _actions[0]->reverse());
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Repeat
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Repeat* Repeat::create(FiniteTimeAction *pAction, unsigned int times)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Repeat* pRepeat = new Repeat();
|
2012-04-19 14:35:52 +08:00
|
|
|
pRepeat->initWithAction(pAction, times);
|
|
|
|
pRepeat->autorelease();
|
|
|
|
|
|
|
|
return pRepeat;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool Repeat::initWithAction(FiniteTimeAction *pAction, unsigned int times)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-06-08 13:55:28 +08:00
|
|
|
float d = pAction->getDuration() * times;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(d))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_times = times;
|
|
|
|
_innerAction = pAction;
|
2012-04-19 14:35:52 +08:00
|
|
|
pAction->retain();
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
_actionInstant = dynamic_cast<ActionInstant*>(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-20 14:13:12 +08:00
|
|
|
Repeat* Repeat::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new Repeat();
|
2013-07-09 05:38:14 +08:00
|
|
|
a->initWithAction( _innerAction->clone(), _times );
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Repeat::~Repeat(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_innerAction);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void Repeat::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_total = 0;
|
|
|
|
_nextDt = _innerAction->getDuration()/_duration;
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_innerAction->startWithTarget(target);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Repeat::stop(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_innerAction->stop();
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInterval::stop();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// issue #80. Instead of hooking step:, hook update: since it can be called by any
|
2013-06-20 14:13:12 +08:00
|
|
|
// container action like Repeat, Sequence, Ease, etc..
|
|
|
|
void Repeat::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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-07 13:01:21 +08:00
|
|
|
bool Repeat::isDone(void) const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _total == _times;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Repeat* Repeat::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return Repeat::create(_innerAction->reverse(), _times);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// RepeatForever
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
RepeatForever::~RepeatForever()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
RepeatForever *RepeatForever::create(ActionInterval *pAction)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
RepeatForever *pRet = new RepeatForever();
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRet && pRet->initWithAction(pAction))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool RepeatForever::initWithAction(ActionInterval *pAction)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(pAction != NULL, "");
|
2012-04-19 14:35:52 +08:00
|
|
|
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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
RepeatForever *RepeatForever::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new RepeatForever();
|
2013-07-08 23:05:47 +08:00
|
|
|
a->initWithAction(_innerAction->clone());
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void RepeatForever::startWithTarget(Node* target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_innerAction->startWithTarget(target);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void RepeatForever::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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-07 13:01:21 +08:00
|
|
|
bool RepeatForever::isDone() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
RepeatForever *RepeatForever::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return RepeatForever::create(_innerAction->reverse());
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Spawn
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Spawn* Spawn::create(FiniteTimeAction *pAction1, ...)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
va_list params;
|
|
|
|
va_start(params, pAction1);
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Spawn *pRet = Spawn::createWithVariableList(pAction1, params);
|
2012-11-15 17:16:51 +08:00
|
|
|
|
|
|
|
va_end(params);
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Spawn* Spawn::createWithVariableList(FiniteTimeAction *pAction1, va_list args)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
FiniteTimeAction *pNow;
|
|
|
|
FiniteTimeAction *pPrev = pAction1;
|
2012-12-10 12:02:24 +08:00
|
|
|
bool bOneAction = true;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
while (pAction1)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
pNow = va_arg(args, FiniteTimeAction*);
|
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-06-20 14:13:12 +08:00
|
|
|
// If only one action is added to Spawn, make up a Spawn by adding a simplest finite time action.
|
2013-02-27 09:38:30 +08:00
|
|
|
if (bOneAction)
|
|
|
|
{
|
|
|
|
pPrev = createWithTwoActions(pPrev, ExtraAction::create());
|
2012-12-10 12:02:24 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
return ((Spawn*)pPrev);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Spawn* Spawn::create(Array *arrayOfActions)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Spawn* pRet = NULL;
|
2013-02-27 09:38:30 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
unsigned int count = arrayOfActions->count();
|
2012-12-10 12:02:24 +08:00
|
|
|
CC_BREAK_IF(count == 0);
|
2013-07-09 05:38:14 +08:00
|
|
|
FiniteTimeAction* prev = static_cast<FiniteTimeAction*>( 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)
|
|
|
|
{
|
2013-07-09 05:38:14 +08:00
|
|
|
prev = createWithTwoActions(prev, static_cast<FiniteTimeAction*>( arrayOfActions->objectAtIndex(i)) );
|
2012-12-10 12:02:24 +08:00
|
|
|
}
|
|
|
|
}
|
2013-02-27 09:38:30 +08:00
|
|
|
else
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
// If only one action is added to Spawn, make up a Spawn by adding a simplest finite time action.
|
2013-02-27 09:38:30 +08:00
|
|
|
prev = createWithTwoActions(prev, ExtraAction::create());
|
|
|
|
}
|
2013-06-20 14:13:12 +08:00
|
|
|
pRet = (Spawn*)prev;
|
2013-02-27 09:38:30 +08:00
|
|
|
}while (0);
|
|
|
|
|
2012-12-10 12:02:24 +08:00
|
|
|
return pRet;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Spawn* Spawn::createWithTwoActions(FiniteTimeAction *pAction1, FiniteTimeAction *pAction2)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Spawn *pSpawn = new Spawn();
|
2012-07-23 22:49:11 +08:00
|
|
|
pSpawn->initWithTwoActions(pAction1, pAction2);
|
2012-04-19 14:35:52 +08:00
|
|
|
pSpawn->autorelease();
|
|
|
|
|
|
|
|
return pSpawn;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool Spawn:: initWithTwoActions(FiniteTimeAction *pAction1, FiniteTimeAction *pAction2)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(pAction1 != NULL, "");
|
|
|
|
CCASSERT(pAction2 != NULL, "");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(MAX(d1, d2)))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
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-20 14:13:12 +08:00
|
|
|
_two = Sequence::createWithTwoActions(pAction2, DelayTime::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-20 14:13:12 +08:00
|
|
|
_one = Sequence::createWithTwoActions(pAction1, DelayTime::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-20 14:13:12 +08:00
|
|
|
Spawn* Spawn::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new Spawn();
|
2013-06-19 06:06:53 +08:00
|
|
|
a->initWithTwoActions(_one->clone(), _two->clone());
|
2013-06-14 08:25:14 +08:00
|
|
|
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Spawn::~Spawn(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_one);
|
|
|
|
CC_SAFE_RELEASE(_two);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void Spawn::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_one->startWithTarget(target);
|
|
|
|
_two->startWithTarget(target);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Spawn::stop(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_one->stop();
|
|
|
|
_two->stop();
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInterval::stop();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Spawn::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-20 14:13:12 +08:00
|
|
|
Spawn* Spawn::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return Spawn::createWithTwoActions(_one->reverse(), _two->reverse());
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// RotateTo
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
RotateTo* RotateTo::create(float fDuration, float fDeltaAngle)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
RotateTo* pRotateTo = new RotateTo();
|
2012-11-15 17:16:51 +08:00
|
|
|
pRotateTo->initWithDuration(fDuration, fDeltaAngle);
|
2012-04-19 14:35:52 +08:00
|
|
|
pRotateTo->autorelease();
|
|
|
|
|
|
|
|
return pRotateTo;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool RotateTo::initWithDuration(float fDuration, float fDeltaAngle)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::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;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
RotateTo* RotateTo::create(float fDuration, float fDeltaAngleX, float fDeltaAngleY)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
RotateTo* pRotateTo = new RotateTo();
|
2012-11-15 17:16:51 +08:00
|
|
|
pRotateTo->initWithDuration(fDuration, fDeltaAngleX, fDeltaAngleY);
|
|
|
|
pRotateTo->autorelease();
|
|
|
|
|
|
|
|
return pRotateTo;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool RotateTo::initWithDuration(float fDuration, float fDeltaAngleX, float fDeltaAngleY)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(fDuration))
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
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-20 14:13:12 +08:00
|
|
|
RotateTo* RotateTo::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new RotateTo();
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void RotateTo::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
2012-11-15 17:16:51 +08:00
|
|
|
|
|
|
|
// Calculate X
|
2013-07-18 07:56:19 +08:00
|
|
|
_startAngleX = target->getRotationX();
|
2013-06-15 14:03:30 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void RotateTo::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-20 14:13:12 +08:00
|
|
|
RotateTo *RotateTo::reverse() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(false, "RotateTo doesn't support the 'reverse' method");
|
2013-06-16 10:44:39 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
|
|
|
// RotateBy
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
RotateBy* RotateBy::create(float fDuration, float fDeltaAngle)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
RotateBy *pRotateBy = new RotateBy();
|
2012-11-15 17:16:51 +08:00
|
|
|
pRotateBy->initWithDuration(fDuration, fDeltaAngle);
|
2012-04-19 14:35:52 +08:00
|
|
|
pRotateBy->autorelease();
|
|
|
|
|
|
|
|
return pRotateBy;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool RotateBy::initWithDuration(float fDuration, float fDeltaAngle)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::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;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
RotateBy* RotateBy::create(float fDuration, float fDeltaAngleX, float fDeltaAngleY)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
RotateBy *pRotateBy = new RotateBy();
|
2012-11-15 17:16:51 +08:00
|
|
|
pRotateBy->initWithDuration(fDuration, fDeltaAngleX, fDeltaAngleY);
|
|
|
|
pRotateBy->autorelease();
|
|
|
|
|
|
|
|
return pRotateBy;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool RotateBy::initWithDuration(float fDuration, float fDeltaAngleX, float fDeltaAngleY)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(fDuration))
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
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-20 14:13:12 +08:00
|
|
|
RotateBy* RotateBy::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new RotateBy();
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void RotateBy::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_startAngleX = target->getRotationX();
|
|
|
|
_startAngleY = target->getRotationY();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void RotateBy::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-20 14:13:12 +08:00
|
|
|
RotateBy* RotateBy::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return RotateBy::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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MoveBy* MoveBy::create(float duration, const Point& deltaPosition)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MoveBy *pRet = new MoveBy();
|
2012-12-26 18:59:31 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool MoveBy::initWithDuration(float duration, const Point& deltaPosition)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_positionDelta = deltaPosition;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MoveBy* MoveBy::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new MoveBy();
|
2013-06-15 14:03:30 +08:00
|
|
|
a->initWithDuration(_duration, _positionDelta);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void MoveBy::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_previousPosition = _startPosition = target->getPosition();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MoveBy* MoveBy::reverse() const
|
2012-12-26 18:59:31 +08:00
|
|
|
{
|
2013-07-12 14:11:55 +08:00
|
|
|
return MoveBy::create(_duration, Point( -_positionDelta.x, -_positionDelta.y));
|
2012-12-26 18:59:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MoveBy::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-20 14:13:12 +08:00
|
|
|
Point currentPos = _target->getPosition();
|
2013-07-11 16:38:58 +08:00
|
|
|
Point diff = currentPos - _previousPosition;
|
|
|
|
_startPosition = _startPosition + diff;
|
|
|
|
Point newPos = _startPosition + (_positionDelta * t);
|
2013-06-15 14:03:30 +08:00
|
|
|
_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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MoveTo* MoveTo::create(float duration, const Point& position)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MoveTo *pRet = new MoveTo();
|
2012-12-26 18:59:31 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool MoveTo::initWithDuration(float duration, const Point& position)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_endPosition = position;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MoveTo* MoveTo::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new MoveTo();
|
2013-06-15 14:03:30 +08:00
|
|
|
a->initWithDuration(_duration, _endPosition);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void MoveTo::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
MoveBy::startWithTarget(target);
|
|
|
|
_positionDelta = _endPosition - target->getPosition();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
// SkewTo
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
SkewTo* SkewTo::create(float t, float sx, float sy)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
SkewTo *pSkewTo = new SkewTo();
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pSkewTo)
|
|
|
|
{
|
|
|
|
if (pSkewTo->initWithDuration(t, sx, sy))
|
|
|
|
{
|
|
|
|
pSkewTo->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pSkewTo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pSkewTo;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool SkewTo::initWithDuration(float t, float sx, float sy)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
bool bRet = false;
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(t))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
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-20 14:13:12 +08:00
|
|
|
SkewTo* SkewTo::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new SkewTo();
|
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;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
SkewTo* SkewTo::reverse() const
|
2013-06-19 06:06:53 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(false, "reverse() not supported in SkewTo");
|
2013-06-19 06:06:53 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void SkewTo::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
_startSkewX = target->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-07-18 07:56:19 +08:00
|
|
|
_startSkewY = target->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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void SkewTo::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
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
SkewTo::SkewTo()
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
// SkewBy
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
SkewBy* SkewBy::create(float t, float sx, float sy)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
SkewBy *pSkewBy = new SkewBy();
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pSkewBy)
|
|
|
|
{
|
|
|
|
if (pSkewBy->initWithDuration(t, sx, sy))
|
|
|
|
{
|
|
|
|
pSkewBy->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pSkewBy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pSkewBy;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
SkewBy * SkewBy::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new SkewBy();
|
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;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool SkewBy::initWithDuration(float t, float deltaSkewX, float deltaSkewY)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
bool bRet = false;
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
if (SkewTo::initWithDuration(t, deltaSkewX, deltaSkewY))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_skewX = deltaSkewX;
|
|
|
|
_skewY = deltaSkewY;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void SkewBy::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
SkewTo::startWithTarget(target);
|
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-20 14:13:12 +08:00
|
|
|
SkewBy* SkewBy::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return SkewBy::create(_duration, -_skewX, -_skewY);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// JumpBy
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-07-20 13:01:27 +08:00
|
|
|
JumpBy* JumpBy::create(float duration, const Point& position, float height, int jumps)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
JumpBy *pJumpBy = new JumpBy();
|
2012-04-19 14:35:52 +08:00
|
|
|
pJumpBy->initWithDuration(duration, position, height, jumps);
|
|
|
|
pJumpBy->autorelease();
|
|
|
|
|
|
|
|
return pJumpBy;
|
|
|
|
}
|
|
|
|
|
2013-07-20 13:01:27 +08:00
|
|
|
bool JumpBy::initWithDuration(float duration, const Point& position, float height, int jumps)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(jumps>=0, "Number of jumps must be >= 0");
|
|
|
|
|
|
|
|
if (ActionInterval::initWithDuration(duration) && jumps>=0)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
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-20 14:13:12 +08:00
|
|
|
JumpBy* JumpBy::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new JumpBy();
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void JumpBy::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_previousPos = _startPosition = target->getPosition();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void JumpBy::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-20 14:13:12 +08:00
|
|
|
Point currentPos = _target->getPosition();
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2013-07-11 16:38:58 +08:00
|
|
|
Point diff = currentPos - _previousPos;
|
|
|
|
_startPosition = diff + _startPosition;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
Point newPos = _startPosition + Point(x,y);
|
2013-06-15 14:03:30 +08:00
|
|
|
_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-07-12 18:04:32 +08:00
|
|
|
_target->setPosition(ccpAdd( _startPosition, Point(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-20 14:13:12 +08:00
|
|
|
JumpBy* JumpBy::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-12 14:11:55 +08:00
|
|
|
return JumpBy::create(_duration, Point(-_delta.x, -_delta.y),
|
2013-06-15 14:03:30 +08:00
|
|
|
_height, _jumps);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// JumpTo
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
JumpTo* JumpTo::create(float duration, const Point& position, float height, int jumps)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
JumpTo *pJumpTo = new JumpTo();
|
2012-04-19 14:35:52 +08:00
|
|
|
pJumpTo->initWithDuration(duration, position, height, jumps);
|
|
|
|
pJumpTo->autorelease();
|
|
|
|
|
|
|
|
return pJumpTo;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
JumpTo* JumpTo::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new JumpTo();
|
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;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
JumpTo* JumpTo::reverse() const
|
2013-06-19 06:06:53 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(false, "reverse() not supported in JumpTo");
|
2013-06-19 06:06:53 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void JumpTo::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
JumpBy::startWithTarget(target);
|
2013-07-12 14:11:55 +08:00
|
|
|
_delta = Point(_delta.x - _startPosition.x, _delta.y - _startPosition.y);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bezier cubic formula:
|
|
|
|
// ((1 - t) + t)3 = 1
|
2013-07-29 14:07:57 +08:00
|
|
|
// Expands to ...
|
2012-04-19 14:35:52 +08:00
|
|
|
// (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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
BezierBy* BezierBy::create(float t, const ccBezierConfig& c)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
BezierBy *pBezierBy = new BezierBy();
|
2012-04-19 14:35:52 +08:00
|
|
|
pBezierBy->initWithDuration(t, c);
|
|
|
|
pBezierBy->autorelease();
|
|
|
|
|
|
|
|
return pBezierBy;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool BezierBy::initWithDuration(float t, const ccBezierConfig& c)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(t))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_config = c;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void BezierBy::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_previousPosition = _startPosition = target->getPosition();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
BezierBy* BezierBy::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new BezierBy();
|
2013-06-15 14:03:30 +08:00
|
|
|
a->initWithDuration(_duration, _config);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void BezierBy::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-20 14:13:12 +08:00
|
|
|
Point currentPos = _target->getPosition();
|
2013-07-11 16:38:58 +08:00
|
|
|
Point diff = currentPos - _previousPosition;
|
|
|
|
_startPosition = _startPosition + diff;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
Point newPos = _startPosition + Point(x,y);
|
2013-06-15 14:03:30 +08:00
|
|
|
_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-07-12 18:04:32 +08:00
|
|
|
_target->setPosition(ccpAdd( _startPosition, Point(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-20 14:13:12 +08:00
|
|
|
BezierBy* BezierBy::reverse(void) const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
ccBezierConfig r;
|
|
|
|
|
2013-07-11 16:38:58 +08:00
|
|
|
r.endPosition = -_config.endPosition;
|
|
|
|
r.controlPoint_1 = _config.controlPoint_2 + (-_config.endPosition);
|
|
|
|
r.controlPoint_2 = _config.controlPoint_1 + (-_config.endPosition);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
BezierBy *pAction = BezierBy::create(_duration, r);
|
2012-04-19 14:35:52 +08:00
|
|
|
return pAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// BezierTo
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
BezierTo* BezierTo::create(float t, const ccBezierConfig& c)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
BezierTo *pBezierTo = new BezierTo();
|
2012-04-19 14:35:52 +08:00
|
|
|
pBezierTo->initWithDuration(t, c);
|
|
|
|
pBezierTo->autorelease();
|
|
|
|
|
|
|
|
return pBezierTo;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool BezierTo::initWithDuration(float t, const ccBezierConfig &c)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(t))
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_toConfig = c;
|
2013-07-11 15:41:05 +08:00
|
|
|
return true;
|
2012-11-15 17:16:51 +08:00
|
|
|
}
|
|
|
|
|
2013-07-11 15:41:05 +08:00
|
|
|
return false;
|
2012-11-15 17:16:51 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
BezierTo* BezierTo::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new BezierTo();
|
2013-07-11 15:41:05 +08:00
|
|
|
a->initWithDuration(_duration, _toConfig);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void BezierTo::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
BezierBy::startWithTarget(target);
|
2013-07-11 16:38:58 +08:00
|
|
|
_config.controlPoint_1 = _toConfig.controlPoint_1 - _startPosition;
|
|
|
|
_config.controlPoint_2 = _toConfig.controlPoint_2 - _startPosition;
|
|
|
|
_config.endPosition = _toConfig.endPosition - _startPosition;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
BezierTo* BezierTo::reverse() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(false, "CCBezierTo doesn't support the 'reverse' method");
|
2013-06-16 10:44:39 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
|
|
|
// ScaleTo
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
ScaleTo* ScaleTo::create(float duration, float s)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
ScaleTo *pScaleTo = new ScaleTo();
|
2012-04-19 14:35:52 +08:00
|
|
|
pScaleTo->initWithDuration(duration, s);
|
|
|
|
pScaleTo->autorelease();
|
|
|
|
|
|
|
|
return pScaleTo;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ScaleTo* ScaleTo::create(float duration, float sx, float sy)
|
2013-06-19 06:06:53 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
ScaleTo *pScaleTo = new ScaleTo();
|
2013-06-19 06:06:53 +08:00
|
|
|
pScaleTo->initWithDuration(duration, sx, sy);
|
|
|
|
pScaleTo->autorelease();
|
|
|
|
|
|
|
|
return pScaleTo;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool ScaleTo::initWithDuration(float duration, float s)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_endScaleX = s;
|
|
|
|
_endScaleY = s;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool ScaleTo::initWithDuration(float duration, float sx, float sy)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
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-20 14:13:12 +08:00
|
|
|
ScaleTo* ScaleTo::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new ScaleTo();
|
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;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ScaleTo* ScaleTo::reverse() const
|
2013-06-19 06:06:53 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(false, "reverse() not supported in ScaleTo");
|
2013-06-19 06:06:53 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void ScaleTo::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_startScaleX = target->getScaleX();
|
|
|
|
_startScaleY = target->getScaleY();
|
2013-06-15 14:03:30 +08:00
|
|
|
_deltaX = _endScaleX - _startScaleX;
|
|
|
|
_deltaY = _endScaleY - _startScaleY;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ScaleTo::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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ScaleBy* ScaleBy::create(float duration, float s)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
ScaleBy *pScaleBy = new ScaleBy();
|
2012-04-19 14:35:52 +08:00
|
|
|
pScaleBy->initWithDuration(duration, s);
|
|
|
|
pScaleBy->autorelease();
|
|
|
|
|
|
|
|
return pScaleBy;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ScaleBy* ScaleBy::create(float duration, float sx, float sy)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
ScaleBy *pScaleBy = new ScaleBy();
|
2012-04-19 14:35:52 +08:00
|
|
|
pScaleBy->initWithDuration(duration, sx, sy);
|
|
|
|
pScaleBy->autorelease();
|
|
|
|
|
|
|
|
return pScaleBy;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ScaleBy* ScaleBy::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new ScaleBy();
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void ScaleBy::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ScaleTo::startWithTarget(target);
|
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-20 14:13:12 +08:00
|
|
|
ScaleBy* ScaleBy::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return ScaleBy::create(_duration, 1 / _endScaleX, 1 / _endScaleY);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Blink
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-07-20 13:01:27 +08:00
|
|
|
Blink* Blink::create(float duration, int blinks)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Blink *pBlink = new Blink();
|
2013-07-20 13:01:27 +08:00
|
|
|
pBlink->initWithDuration(duration, blinks);
|
2012-04-19 14:35:52 +08:00
|
|
|
pBlink->autorelease();
|
|
|
|
|
|
|
|
return pBlink;
|
|
|
|
}
|
|
|
|
|
2013-07-20 13:01:27 +08:00
|
|
|
bool Blink::initWithDuration(float duration, int blinks)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(blinks>=0, "blinks should be >= 0");
|
|
|
|
|
|
|
|
if (ActionInterval::initWithDuration(duration) && blinks>=0)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
_times = blinks;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Blink::stop()
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->setVisible(_originalState);
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInterval::stop();
|
2012-11-15 17:16:51 +08:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void Blink::startWithTarget(Node *target)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_originalState = target->isVisible();
|
2012-11-15 17:16:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Blink* Blink::clone(void) const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new Blink();
|
2013-07-20 13:01:27 +08:00
|
|
|
a->initWithDuration(_duration, _times);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Blink::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-20 14:13:12 +08:00
|
|
|
Blink* Blink::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return Blink::create(_duration, _times);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// FadeIn
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeIn* FadeIn::create(float d)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeIn* pAction = new FadeIn();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
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-20 14:13:12 +08:00
|
|
|
FadeIn* FadeIn::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new FadeIn();
|
2013-07-10 11:58:07 +08:00
|
|
|
a->initWithDuration(_duration);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void FadeIn::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(_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-20 14:13:12 +08:00
|
|
|
ActionInterval* FadeIn::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return FadeOut::create(_duration);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// FadeOut
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeOut* FadeOut::create(float d)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeOut* pAction = new FadeOut();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
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-20 14:13:12 +08:00
|
|
|
FadeOut* FadeOut::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new FadeOut();
|
2013-07-10 14:16:42 +08:00
|
|
|
a->initWithDuration(_duration);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void FadeOut::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(_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-20 14:13:12 +08:00
|
|
|
ActionInterval* FadeOut::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return FadeIn::create(_duration);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// FadeTo
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeTo* FadeTo::create(float duration, GLubyte opacity)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeTo *pFadeTo = new FadeTo();
|
2012-04-19 14:35:52 +08:00
|
|
|
pFadeTo->initWithDuration(duration, opacity);
|
|
|
|
pFadeTo->autorelease();
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
return pFadeTo;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool FadeTo::initWithDuration(float duration, GLubyte opacity)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_toOpacity = opacity;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeTo* FadeTo::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new FadeTo();
|
2013-06-15 14:03:30 +08:00
|
|
|
a->initWithDuration(_duration, _toOpacity);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeTo* FadeTo::reverse() const
|
2013-06-19 06:06:53 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(false, "reverse() not supported in FadeTo");
|
2013-06-19 06:06:53 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void FadeTo::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(target);
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRGBAProtocol)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_fromOpacity = pRGBAProtocol->getOpacity();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-07-18 07:56:19 +08:00
|
|
|
/*_fromOpacity = target->getOpacity();*/
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void FadeTo::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(_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
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
TintTo* TintTo::create(float duration, GLubyte red, GLubyte green, GLubyte blue)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
TintTo *pTintTo = new TintTo();
|
2012-04-19 14:35:52 +08:00
|
|
|
pTintTo->initWithDuration(duration, red, green, blue);
|
|
|
|
pTintTo->autorelease();
|
|
|
|
|
|
|
|
return pTintTo;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool TintTo::initWithDuration(float duration, GLubyte red, GLubyte green, GLubyte blue)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-05 16:49:22 +08:00
|
|
|
_to = Color3B(red, green, blue);
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TintTo* TintTo::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new TintTo();
|
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;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TintTo* TintTo::reverse() const
|
2013-06-19 06:06:53 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(false, "reverse() not supported in TintTo");
|
2013-06-19 06:06:53 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void TintTo::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
2013-06-20 14:13:12 +08:00
|
|
|
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(_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-07-18 07:56:19 +08:00
|
|
|
/*_from = target->getColor();*/
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void TintTo::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(_target);
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRGBAProtocol)
|
|
|
|
{
|
2013-07-05 16:49:22 +08:00
|
|
|
pRGBAProtocol->setColor(Color3B(GLubyte(_from.r + (_to.r - _from.r) * time),
|
2013-07-22 14:45:01 +08:00
|
|
|
(GLubyte)(_from.g + (_to.g - _from.g) * time),
|
|
|
|
(GLubyte)(_from.b + (_to.b - _from.b) * time)));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// TintBy
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TintBy* TintBy::create(float duration, GLshort deltaRed, GLshort deltaGreen, GLshort deltaBlue)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
TintBy *pTintBy = new TintBy();
|
2012-04-19 14:35:52 +08:00
|
|
|
pTintBy->initWithDuration(duration, deltaRed, deltaGreen, deltaBlue);
|
|
|
|
pTintBy->autorelease();
|
|
|
|
|
|
|
|
return pTintBy;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool TintBy::initWithDuration(float duration, GLshort deltaRed, GLshort deltaGreen, GLshort deltaBlue)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
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-20 14:13:12 +08:00
|
|
|
TintBy* TintBy::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new TintBy();
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void TintBy::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(target);
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRGBAProtocol)
|
|
|
|
{
|
2013-07-05 16:49:22 +08:00
|
|
|
Color3B 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void TintBy::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
RGBAProtocol *pRGBAProtocol = dynamic_cast<RGBAProtocol*>(_target);
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pRGBAProtocol)
|
|
|
|
{
|
2013-07-05 16:49:22 +08:00
|
|
|
pRGBAProtocol->setColor(Color3B((GLubyte)(_fromR + _deltaR * time),
|
2013-06-15 14:03:30 +08:00
|
|
|
(GLubyte)(_fromG + _deltaG * time),
|
|
|
|
(GLubyte)(_fromB + _deltaB * time)));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TintBy* TintBy::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return TintBy::create(_duration, -_deltaR, -_deltaG, -_deltaB);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// DelayTime
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
DelayTime* DelayTime::create(float d)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
DelayTime* pAction = new DelayTime();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
pAction->initWithDuration(d);
|
|
|
|
pAction->autorelease();
|
|
|
|
|
|
|
|
return pAction;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
DelayTime* DelayTime::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new DelayTime();
|
2013-07-10 14:16:42 +08:00
|
|
|
a->initWithDuration(_duration);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void DelayTime::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CC_UNUSED_PARAM(time);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
DelayTime* DelayTime::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return DelayTime::create(_duration);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ReverseTime
|
|
|
|
//
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ReverseTime* ReverseTime::create(FiniteTimeAction *pAction)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// casting to prevent warnings
|
2013-06-20 14:13:12 +08:00
|
|
|
ReverseTime *pReverseTime = new ReverseTime();
|
2013-06-16 09:54:34 +08:00
|
|
|
pReverseTime->initWithAction( pAction->clone() );
|
2012-04-19 14:35:52 +08:00
|
|
|
pReverseTime->autorelease();
|
|
|
|
|
|
|
|
return pReverseTime;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool ReverseTime::initWithAction(FiniteTimeAction *pAction)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(pAction != NULL, "");
|
|
|
|
CCASSERT(pAction != _other, "");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(pAction->getDuration()))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// 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-20 14:13:12 +08:00
|
|
|
ReverseTime* ReverseTime::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new ReverseTime();
|
2013-06-19 00:59:34 +08:00
|
|
|
a->initWithAction( _other->clone() );
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ReverseTime::ReverseTime() : _other(NULL)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ReverseTime::~ReverseTime(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_other);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void ReverseTime::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_other->startWithTarget(target);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ReverseTime::stop(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_other->stop();
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInterval::stop();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ReverseTime::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-20 14:13:12 +08:00
|
|
|
ReverseTime* ReverseTime::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-09 05:38:14 +08:00
|
|
|
// XXX: This looks like a bug
|
2013-06-20 14:13:12 +08:00
|
|
|
return (ReverseTime*)_other->clone();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Animate
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
Animate* Animate::create(Animation *pAnimation)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Animate *pAnimate = new Animate();
|
2012-04-19 14:35:52 +08:00
|
|
|
pAnimate->initWithAnimation(pAnimation);
|
|
|
|
pAnimate->autorelease();
|
|
|
|
|
|
|
|
return pAnimate;
|
|
|
|
}
|
|
|
|
|
2013-07-20 04:16:38 +08:00
|
|
|
Animate::Animate()
|
2013-07-29 14:07:57 +08:00
|
|
|
: _splitTimes(new std::vector<float>)
|
2013-07-20 04:16:38 +08:00
|
|
|
, _nextFrame(0)
|
|
|
|
, _origFrame(NULL)
|
|
|
|
, _executedLoops(0)
|
2013-07-29 14:07:57 +08:00
|
|
|
, _animation(NULL)
|
2013-07-20 04:16:38 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Animate::~Animate()
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(_animation);
|
|
|
|
CC_SAFE_RELEASE(_origFrame);
|
|
|
|
CC_SAFE_DELETE(_splitTimes);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool Animate::initWithAnimation(Animation *pAnimation)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT( pAnimation!=NULL, "Animate: argument Animation must be non-NULL");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
float singleDuration = pAnimation->getDuration();
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
if ( ActionInterval::initWithDuration(singleDuration * pAnimation->getLoops() ) )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
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();
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Array* pFrames = pAnimation->getFrames();
|
|
|
|
CCARRAY_VERIFY_TYPE(pFrames, AnimationFrame*);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Object* pObj = NULL;
|
2012-04-19 14:35:52 +08:00
|
|
|
CCARRAY_FOREACH(pFrames, pObj)
|
|
|
|
{
|
2013-07-09 14:29:51 +08:00
|
|
|
AnimationFrame* frame = static_cast<AnimationFrame*>(pObj);
|
2012-04-19 14:35:52 +08:00
|
|
|
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-07-20 04:16:38 +08:00
|
|
|
void Animate::setAnimation(cocos2d::Animation *animation)
|
|
|
|
{
|
|
|
|
if (_animation != animation)
|
|
|
|
{
|
|
|
|
CC_SAFE_RETAIN(animation);
|
|
|
|
CC_SAFE_RELEASE(_animation);
|
|
|
|
_animation = animation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Animate* Animate::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new Animate();
|
2013-06-19 06:06:53 +08:00
|
|
|
a->initWithAnimation(_animation->clone());
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void Animate::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
Sprite *pSprite = static_cast<Sprite*>(target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Animate::stop(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_animation->getRestoreOriginalFrame() && _target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-09 05:38:14 +08:00
|
|
|
static_cast<Sprite*>(_target)->setDisplayFrame(_origFrame);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInterval::stop();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Animate::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-20 14:13:12 +08:00
|
|
|
Array* frames = _animation->getFrames();
|
2012-04-19 14:35:52 +08:00
|
|
|
unsigned int numberOfFrames = frames->count();
|
2013-06-20 14:13:12 +08:00
|
|
|
SpriteFrame *frameToDisplay = NULL;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-20 13:01:27 +08:00
|
|
|
for( int i=_nextFrame; i < numberOfFrames; i++ ) {
|
2013-06-15 14:03:30 +08:00
|
|
|
float splitTime = _splitTimes->at(i);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
if( splitTime <= t ) {
|
2013-07-09 05:38:14 +08:00
|
|
|
AnimationFrame* frame = static_cast<AnimationFrame*>(frames->objectAtIndex(i));
|
2012-04-19 14:35:52 +08:00
|
|
|
frameToDisplay = frame->getSpriteFrame();
|
2013-07-09 05:38:14 +08:00
|
|
|
static_cast<Sprite*>(_target)->setDisplayFrame(frameToDisplay);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Dictionary* dict = frame->getUserInfo();
|
2012-04-19 14:35:52 +08:00
|
|
|
if( dict )
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
//TODO: [[NSNotificationCenter defaultCenter] postNotificationName:AnimationFrameDisplayedNotification object:target_ userInfo:dict];
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
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-20 14:13:12 +08:00
|
|
|
Animate* Animate::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Array* pOldArray = _animation->getFrames();
|
|
|
|
Array* pNewArray = Array::createWithCapacity(pOldArray->count());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
CCARRAY_VERIFY_TYPE(pOldArray, AnimationFrame*);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
if (pOldArray->count() > 0)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Object* pObj = NULL;
|
2012-04-19 14:35:52 +08:00
|
|
|
CCARRAY_FOREACH_REVERSE(pOldArray, pObj)
|
|
|
|
{
|
2013-07-09 05:38:14 +08:00
|
|
|
AnimationFrame* pElement = static_cast<AnimationFrame*>(pObj);
|
2012-04-19 14:35:52 +08:00
|
|
|
if (! pElement)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-06-19 06:06:53 +08:00
|
|
|
pNewArray->addObject(pElement->clone());
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Animation *newAnim = Animation::create(pNewArray, _animation->getDelayPerUnit(), _animation->getLoops());
|
2013-06-15 14:03:30 +08:00
|
|
|
newAnim->setRestoreOriginalFrame(_animation->getRestoreOriginalFrame());
|
2013-06-20 14:13:12 +08:00
|
|
|
return Animate::create(newAnim);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// TargetedAction
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TargetedAction::TargetedAction()
|
2013-07-29 14:07:57 +08:00
|
|
|
: _action(NULL)
|
|
|
|
, _forcedTarget(NULL)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TargetedAction::~TargetedAction()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_forcedTarget);
|
|
|
|
CC_SAFE_RELEASE(_action);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
TargetedAction* TargetedAction::create(Node* target, FiniteTimeAction* pAction)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
TargetedAction* p = new TargetedAction();
|
2013-07-18 07:56:19 +08:00
|
|
|
p->initWithTarget(target, pAction);
|
2012-04-19 14:35:52 +08:00
|
|
|
p->autorelease();
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
bool TargetedAction::initWithTarget(Node* target, FiniteTimeAction* pAction)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if(ActionInterval::initWithDuration(pAction->getDuration()))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
CC_SAFE_RETAIN(target);
|
|
|
|
_forcedTarget = target;
|
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-20 14:13:12 +08:00
|
|
|
TargetedAction* TargetedAction::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new TargetedAction();
|
2013-06-15 14:03:30 +08:00
|
|
|
// win32 : use the _other's copy object.
|
2013-06-19 06:06:53 +08:00
|
|
|
a->initWithTarget(_forcedTarget, _action->clone());
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TargetedAction* TargetedAction::reverse(void) const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2013-08-01 10:07:40 +08:00
|
|
|
// just reverse the internal action
|
|
|
|
auto a = new TargetedAction();
|
|
|
|
a->initWithTarget(_forcedTarget, _action->reverse());
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void TargetedAction::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
2013-06-15 14:03:30 +08:00
|
|
|
_action->startWithTarget(_forcedTarget);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void TargetedAction::stop(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_action->stop();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void TargetedAction::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
|
|
|
}
|
|
|
|
|
2013-07-20 04:16:38 +08:00
|
|
|
void TargetedAction::setForcedTarget(Node* forcedTarget)
|
|
|
|
{
|
|
|
|
if( _forcedTarget != forcedTarget ) {
|
|
|
|
CC_SAFE_RETAIN(forcedTarget);
|
|
|
|
CC_SAFE_RELEASE(_forcedTarget);
|
|
|
|
_forcedTarget = forcedTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|