2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CCActionInterval.h"
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCSprite.h"
|
|
|
|
#include "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()
|
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
ExtraAction* ret = new ExtraAction();
|
|
|
|
if (ret)
|
2012-12-10 12:02:24 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
ret->autorelease();
|
2012-12-10 12:02:24 +08:00
|
|
|
}
|
2013-12-18 17:47:20 +08:00
|
|
|
return ret;
|
2012-12-10 12:02:24 +08:00
|
|
|
}
|
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-11-22 09:06:06 +08:00
|
|
|
Sequence* Sequence::createWithTwoActions(FiniteTimeAction *actionOne, FiniteTimeAction *actionTwo)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-22 09:06:06 +08:00
|
|
|
Sequence *sequence = new Sequence();
|
|
|
|
sequence->initWithTwoActions(actionOne, actionTwo);
|
|
|
|
sequence->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-11-22 09:06:06 +08:00
|
|
|
return sequence;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-03-25 06:09:24 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
|
|
|
Sequence* Sequence::variadicCreate(FiniteTimeAction *action1, ...)
|
|
|
|
{
|
|
|
|
va_list params;
|
|
|
|
va_start(params, action1);
|
|
|
|
|
|
|
|
Sequence *ret = Sequence::createWithVariableList(action1, params);
|
|
|
|
|
|
|
|
va_end(params);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else
|
2013-12-18 17:47:20 +08:00
|
|
|
Sequence* Sequence::create(FiniteTimeAction *action1, ...)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
va_list params;
|
2013-12-18 17:47:20 +08:00
|
|
|
va_start(params, action1);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
Sequence *ret = Sequence::createWithVariableList(action1, params);
|
2012-11-15 17:16:51 +08:00
|
|
|
|
|
|
|
va_end(params);
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return ret;
|
2012-11-15 17:16:51 +08:00
|
|
|
}
|
2014-03-25 06:09:24 +08:00
|
|
|
#endif
|
2012-11-15 17:16:51 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
Sequence* Sequence::createWithVariableList(FiniteTimeAction *action1, va_list args)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
FiniteTimeAction *now;
|
|
|
|
FiniteTimeAction *prev = action1;
|
2012-12-10 12:02:24 +08:00
|
|
|
bool bOneAction = true;
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
while (action1)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
now = va_arg(args, FiniteTimeAction*);
|
|
|
|
if (now)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
prev = createWithTwoActions(prev, now);
|
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)
|
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
prev = createWithTwoActions(prev, ExtraAction::create());
|
2012-12-10 12:02:24 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-15 17:16:51 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return ((Sequence*)prev);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-11-28 11:04:39 +08:00
|
|
|
Sequence* Sequence::create(const Vector<FiniteTimeAction*>& arrayOfActions)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
Sequence* ret = nullptr;
|
2012-12-10 11:10:11 +08:00
|
|
|
do
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-05 17:19:01 +08:00
|
|
|
auto count = arrayOfActions.size();
|
2012-12-10 11:10:11 +08:00
|
|
|
CC_BREAK_IF(count == 0);
|
|
|
|
|
2013-12-05 10:35:10 +08:00
|
|
|
auto prev = arrayOfActions.at(0);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-12-10 11:10:11 +08:00
|
|
|
if (count > 1)
|
|
|
|
{
|
2013-12-05 17:19:01 +08:00
|
|
|
for (int i = 1; i < count; ++i)
|
2012-12-10 11:10:11 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
prev = createWithTwoActions(prev, arrayOfActions.at(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-12-18 17:47:20 +08:00
|
|
|
ret = static_cast<Sequence*>(prev);
|
2012-12-10 11:10:11 +08:00
|
|
|
}while (0);
|
2013-12-18 17:47:20 +08:00
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool Sequence::initWithTwoActions(FiniteTimeAction *actionOne, FiniteTimeAction *actionTwo)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT(actionOne != nullptr, "");
|
|
|
|
CCASSERT(actionTwo != nullptr, "");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
float d = actionOne->getDuration() + actionTwo->getDuration();
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInterval::initWithDuration(d);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
_actions[0] = actionOne;
|
|
|
|
actionOne->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
_actions[1] = actionTwo;
|
|
|
|
actionTwo->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
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-12-18 17:47:20 +08:00
|
|
|
Repeat* Repeat::create(FiniteTimeAction *action, unsigned int times)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
Repeat* repeat = new Repeat();
|
|
|
|
repeat->initWithAction(action, times);
|
|
|
|
repeat->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return repeat;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool Repeat::initWithAction(FiniteTimeAction *action, unsigned int times)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
float d = action->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;
|
2013-12-18 17:47:20 +08:00
|
|
|
_innerAction = action;
|
|
|
|
action->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
_actionInstant = dynamic_cast<ActionInstant*>(action) ? 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-12-18 17:47:20 +08:00
|
|
|
RepeatForever *RepeatForever::create(ActionInterval *action)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
RepeatForever *ret = new RepeatForever();
|
|
|
|
if (ret && ret->initWithAction(action))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-12-18 17:47:20 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
return nullptr;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool RepeatForever::initWithAction(ActionInterval *action)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT(action != nullptr, "");
|
|
|
|
action->retain();
|
|
|
|
_innerAction = action;
|
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
|
|
|
|
2014-03-25 06:09:24 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
|
|
|
Spawn* Spawn::variadicCreate(FiniteTimeAction *action1, ...)
|
|
|
|
{
|
|
|
|
va_list params;
|
|
|
|
va_start(params, action1);
|
|
|
|
|
|
|
|
Spawn *ret = Spawn::createWithVariableList(action1, params);
|
|
|
|
|
|
|
|
va_end(params);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else
|
2013-12-18 17:47:20 +08:00
|
|
|
Spawn* Spawn::create(FiniteTimeAction *action1, ...)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
va_list params;
|
2013-12-18 17:47:20 +08:00
|
|
|
va_start(params, action1);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
Spawn *ret = Spawn::createWithVariableList(action1, params);
|
2012-11-15 17:16:51 +08:00
|
|
|
|
|
|
|
va_end(params);
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return ret;
|
2012-11-15 17:16:51 +08:00
|
|
|
}
|
2014-03-25 06:09:24 +08:00
|
|
|
#endif
|
2012-11-15 17:16:51 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
Spawn* Spawn::createWithVariableList(FiniteTimeAction *action1, va_list args)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
FiniteTimeAction *now;
|
|
|
|
FiniteTimeAction *prev = action1;
|
|
|
|
bool oneAction = true;
|
2012-12-10 12:02:24 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
while (action1)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
now = va_arg(args, FiniteTimeAction*);
|
|
|
|
if (now)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
prev = createWithTwoActions(prev, now);
|
|
|
|
oneAction = 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-12-18 17:47:20 +08:00
|
|
|
if (oneAction)
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
prev = createWithTwoActions(prev, ExtraAction::create());
|
2012-12-10 12:02:24 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return ((Spawn*)prev);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-11-28 11:04:39 +08:00
|
|
|
Spawn* Spawn::create(const Vector<FiniteTimeAction*>& arrayOfActions)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
Spawn* ret = nullptr;
|
2013-02-27 09:38:30 +08:00
|
|
|
do
|
|
|
|
{
|
2013-12-05 17:19:01 +08:00
|
|
|
auto count = arrayOfActions.size();
|
2012-12-10 12:02:24 +08:00
|
|
|
CC_BREAK_IF(count == 0);
|
2013-12-05 10:35:10 +08:00
|
|
|
auto prev = arrayOfActions.at(0);
|
2013-02-27 09:38:30 +08:00
|
|
|
if (count > 1)
|
2012-12-10 12:02:24 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
for (int i = 1; i < arrayOfActions.size(); ++i)
|
2012-12-10 12:02:24 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
prev = createWithTwoActions(prev, arrayOfActions.at(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-12-18 17:47:20 +08:00
|
|
|
ret = static_cast<Spawn*>(prev);
|
2013-02-27 09:38:30 +08:00
|
|
|
}while (0);
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-11-22 09:06:06 +08:00
|
|
|
Spawn* Spawn::createWithTwoActions(FiniteTimeAction *action1, FiniteTimeAction *action2)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-22 09:06:06 +08:00
|
|
|
Spawn *spawn = new Spawn();
|
|
|
|
spawn->initWithTwoActions(action1, action2);
|
|
|
|
spawn->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-11-22 09:06:06 +08:00
|
|
|
return spawn;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool Spawn::initWithTwoActions(FiniteTimeAction *action1, FiniteTimeAction *action2)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT(action1 != nullptr, "");
|
|
|
|
CCASSERT(action2 != nullptr, "");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool ret = false;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
float d1 = action1->getDuration();
|
|
|
|
float d2 = action2->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-12-18 17:47:20 +08:00
|
|
|
_one = action1;
|
|
|
|
_two = action2;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
if (d1 > d2)
|
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
_two = Sequence::createWithTwoActions(action2, 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-12-18 17:47:20 +08:00
|
|
|
_one = Sequence::createWithTwoActions(action1, 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
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
ret = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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-12-18 17:47:20 +08:00
|
|
|
RotateTo* RotateTo::create(float duration, float deltaAngle)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
RotateTo* rotateTo = new RotateTo();
|
|
|
|
rotateTo->initWithDuration(duration, deltaAngle);
|
|
|
|
rotateTo->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return rotateTo;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool RotateTo::initWithDuration(float duration, float deltaAngle)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
_dstAngleX = _dstAngleY = deltaAngle;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
RotateTo* RotateTo::create(float duration, float deltaAngleX, float deltaAngleY)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
RotateTo* rotateTo = new RotateTo();
|
|
|
|
rotateTo->initWithDuration(duration, deltaAngleX, deltaAngleY);
|
|
|
|
rotateTo->autorelease();
|
2012-11-15 17:16:51 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return rotateTo;
|
2012-11-15 17:16:51 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool RotateTo::initWithDuration(float duration, float deltaAngleX, float deltaAngleY)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
_dstAngleX = deltaAngleX;
|
|
|
|
_dstAngleY = deltaAngleY;
|
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
|
2014-02-23 11:16:42 +08:00
|
|
|
_startAngleX = target->getRotationSkewX();
|
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
|
2014-02-23 11:16:42 +08:00
|
|
|
_startAngleY = _target->getRotationSkewY();
|
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
|
|
|
{
|
2014-02-23 11:16:42 +08:00
|
|
|
_target->setRotationSkewX(_startAngleX + _diffAngleX * time);
|
|
|
|
_target->setRotationSkewY(_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-12-18 17:47:20 +08:00
|
|
|
RotateBy* RotateBy::create(float duration, float deltaAngle)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
RotateBy *rotateBy = new RotateBy();
|
|
|
|
rotateBy->initWithDuration(duration, deltaAngle);
|
|
|
|
rotateBy->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return rotateBy;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
RotateBy* RotateBy::create(float duration, float deltaAngleX, float deltaAngleY)
|
|
|
|
{
|
|
|
|
RotateBy *rotateBy = new RotateBy();
|
|
|
|
rotateBy->initWithDuration(duration, deltaAngleX, deltaAngleY);
|
|
|
|
rotateBy->autorelease();
|
|
|
|
|
|
|
|
return rotateBy;
|
|
|
|
}
|
|
|
|
|
2014-04-02 15:06:16 +08:00
|
|
|
RotateBy* RotateBy::create(float duration, const Vector3& deltaAngle3D)
|
2014-02-23 11:16:42 +08:00
|
|
|
{
|
|
|
|
RotateBy *rotateBy = new RotateBy();
|
|
|
|
rotateBy->initWithDuration(duration, deltaAngle3D);
|
|
|
|
rotateBy->autorelease();
|
|
|
|
|
|
|
|
return rotateBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
RotateBy::RotateBy()
|
|
|
|
: _is3D(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool RotateBy::initWithDuration(float duration, float deltaAngle)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-02-23 11:16:42 +08:00
|
|
|
_angleZ_X = _angleZ_Y = deltaAngle;
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
bool RotateBy::initWithDuration(float duration, float deltaAngleX, float deltaAngleY)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2014-02-23 11:16:42 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
|
|
|
{
|
|
|
|
_angleZ_X = deltaAngleX;
|
|
|
|
_angleZ_Y = deltaAngleY;
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-15 17:16:51 +08:00
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
return false;
|
2012-11-15 17:16:51 +08:00
|
|
|
}
|
|
|
|
|
2014-04-02 15:06:16 +08:00
|
|
|
bool RotateBy::initWithDuration(float duration, const Vector3& deltaAngle3D)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2014-02-23 11:16:42 +08:00
|
|
|
_angle3D = deltaAngle3D;
|
|
|
|
_is3D = true;
|
2012-11-15 17:16:51 +08:00
|
|
|
return true;
|
|
|
|
}
|
2014-02-23 11:16:42 +08:00
|
|
|
|
2012-11-15 17:16:51 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
|
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();
|
2014-02-23 11:16:42 +08:00
|
|
|
if(_is3D)
|
|
|
|
a->initWithDuration(_duration, _angle3D);
|
|
|
|
else
|
|
|
|
a->initWithDuration(_duration, _angleZ_X, _angleZ_Y);
|
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);
|
2014-02-23 11:16:42 +08:00
|
|
|
if(_is3D)
|
|
|
|
{
|
|
|
|
_startAngle3D = target->getRotation3D();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_startAngleZ_X = target->getRotationSkewX();
|
|
|
|
_startAngleZ_Y = target->getRotationSkewY();
|
|
|
|
}
|
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
|
|
|
{
|
2014-02-23 11:16:42 +08:00
|
|
|
if(_is3D)
|
|
|
|
{
|
2014-04-02 15:06:16 +08:00
|
|
|
Vector3 v;
|
2014-02-23 11:16:42 +08:00
|
|
|
v.x = _startAngle3D.x + _angle3D.x * time;
|
|
|
|
v.y = _startAngle3D.y + _angle3D.y * time;
|
|
|
|
v.z = _startAngle3D.z + _angle3D.z * time;
|
|
|
|
_target->setRotation3D(v);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_target->setRotationSkewX(_startAngleZ_X + _angleZ_X * time);
|
|
|
|
_target->setRotationSkewY(_startAngleZ_Y + _angleZ_Y * 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
|
|
|
{
|
2014-02-23 11:16:42 +08:00
|
|
|
if(_is3D)
|
|
|
|
{
|
2014-04-02 15:06:16 +08:00
|
|
|
Vector3 v;
|
2014-02-23 11:16:42 +08:00
|
|
|
v.x = - _angle3D.x;
|
|
|
|
v.y = - _angle3D.y;
|
|
|
|
v.z = - _angle3D.z;
|
|
|
|
return RotateBy::create(_duration, v);
|
|
|
|
}
|
|
|
|
return RotateBy::create(_duration, -_angleZ_X, -_angleZ_Y);
|
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
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
MoveBy* MoveBy::create(float duration, const Vector2& deltaPosition)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
MoveBy *ret = new MoveBy();
|
|
|
|
ret->initWithDuration(duration, deltaPosition);
|
|
|
|
ret->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
bool MoveBy::initWithDuration(float duration, const Vector2& 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
|
|
|
{
|
2014-04-15 18:13:57 +08:00
|
|
|
return MoveBy::create(_duration, Vector2( -_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
|
2014-04-15 18:13:57 +08:00
|
|
|
Vector2 currentPos = _target->getPosition();
|
|
|
|
Vector2 diff = currentPos - _previousPosition;
|
2013-07-11 16:38:58 +08:00
|
|
|
_startPosition = _startPosition + diff;
|
2014-04-15 18:13:57 +08:00
|
|
|
Vector2 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
|
2014-04-22 13:38:15 +08:00
|
|
|
_target->setPosition(_startPosition + _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
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
MoveTo* MoveTo::create(float duration, const Vector2& position)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
MoveTo *ret = new MoveTo();
|
|
|
|
ret->initWithDuration(duration, position);
|
|
|
|
ret->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
bool MoveTo::initWithDuration(float duration, const Vector2& 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-12-18 17:47:20 +08:00
|
|
|
SkewTo *skewTo = new SkewTo();
|
|
|
|
if (skewTo)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if (skewTo->initWithDuration(t, sx, sy))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
skewTo->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CC_SAFE_DELETE(skewTo);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return skewTo;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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-12-18 17:47:20 +08:00
|
|
|
SkewBy *skewBy = new SkewBy();
|
|
|
|
if (skewBy)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if (skewBy->initWithDuration(t, sx, sy))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
skewBy->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CC_SAFE_DELETE(skewBy);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return skewBy;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
bool ret = false;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
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
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
ret = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
JumpBy* JumpBy::create(float duration, const Vector2& position, float height, int jumps)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
JumpBy *jumpBy = new JumpBy();
|
|
|
|
jumpBy->initWithDuration(duration, position, height, jumps);
|
|
|
|
jumpBy->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return jumpBy;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
bool JumpBy::initWithDuration(float duration, const Vector2& 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
|
2014-04-15 18:13:57 +08:00
|
|
|
Vector2 currentPos = _target->getPosition();
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
Vector2 diff = currentPos - _previousPos;
|
2013-07-11 16:38:58 +08:00
|
|
|
_startPosition = diff + _startPosition;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
Vector2 newPos = _startPosition + Vector2(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
|
2014-04-23 14:46:14 +08:00
|
|
|
_target->setPosition(_startPosition + Vector2(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
|
|
|
{
|
2014-04-15 18:13:57 +08:00
|
|
|
return JumpBy::create(_duration, Vector2(-_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
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
JumpTo* JumpTo::create(float duration, const Vector2& position, float height, int jumps)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
JumpTo *jumpTo = new JumpTo();
|
|
|
|
jumpTo->initWithDuration(duration, position, height, jumps);
|
|
|
|
jumpTo->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return jumpTo;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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);
|
2014-04-15 18:13:57 +08:00
|
|
|
_delta = Vector2(_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-12-18 17:47:20 +08:00
|
|
|
BezierBy *bezierBy = new BezierBy();
|
|
|
|
bezierBy->initWithDuration(t, c);
|
|
|
|
bezierBy->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return bezierBy;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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
|
2014-04-15 18:13:57 +08:00
|
|
|
Vector2 currentPos = _target->getPosition();
|
|
|
|
Vector2 diff = currentPos - _previousPosition;
|
2013-07-11 16:38:58 +08:00
|
|
|
_startPosition = _startPosition + diff;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
Vector2 newPos = _startPosition + Vector2(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
|
2014-04-23 14:46:14 +08:00
|
|
|
_target->setPosition( _startPosition + Vector2(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-12-18 17:47:20 +08:00
|
|
|
BezierBy *action = BezierBy::create(_duration, r);
|
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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-12-18 17:47:20 +08:00
|
|
|
BezierTo *bezierTo = new BezierTo();
|
|
|
|
bezierTo->initWithDuration(t, c);
|
|
|
|
bezierTo->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return bezierTo;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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-12-18 17:47:20 +08:00
|
|
|
ScaleTo *scaleTo = new ScaleTo();
|
|
|
|
scaleTo->initWithDuration(duration, s);
|
|
|
|
scaleTo->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return scaleTo;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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-12-18 17:47:20 +08:00
|
|
|
ScaleTo *scaleTo = new ScaleTo();
|
|
|
|
scaleTo->initWithDuration(duration, sx, sy);
|
|
|
|
scaleTo->autorelease();
|
2013-06-19 06:06:53 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return scaleTo;
|
2013-06-19 06:06:53 +08:00
|
|
|
}
|
|
|
|
|
2014-03-19 16:23:14 +08:00
|
|
|
ScaleTo* ScaleTo::create(float duration, float sx, float sy, float sz)
|
|
|
|
{
|
|
|
|
ScaleTo *scaleTo = new ScaleTo();
|
|
|
|
scaleTo->initWithDuration(duration, sx, sy, sz);
|
|
|
|
scaleTo->autorelease();
|
|
|
|
|
|
|
|
return scaleTo;
|
|
|
|
}
|
|
|
|
|
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;
|
2014-03-19 16:23:14 +08:00
|
|
|
_endScaleZ = 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;
|
2014-03-19 16:23:14 +08:00
|
|
|
_endScaleZ = 1.f;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScaleTo::initWithDuration(float duration, float sx, float sy, float sz)
|
|
|
|
{
|
|
|
|
if (ActionInterval::initWithDuration(duration))
|
|
|
|
{
|
|
|
|
_endScaleX = sx;
|
|
|
|
_endScaleY = sy;
|
|
|
|
_endScaleZ = sz;
|
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();
|
2014-03-19 16:23:14 +08:00
|
|
|
a->initWithDuration(_duration, _endScaleX, _endScaleY, _endScaleZ);
|
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();
|
2014-03-19 16:23:14 +08:00
|
|
|
_startScaleZ = target->getScaleZ();
|
2013-06-15 14:03:30 +08:00
|
|
|
_deltaX = _endScaleX - _startScaleX;
|
|
|
|
_deltaY = _endScaleY - _startScaleY;
|
2014-03-19 16:23:14 +08:00
|
|
|
_deltaZ = _endScaleZ - _startScaleZ;
|
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);
|
2014-03-19 16:23:14 +08:00
|
|
|
_target->setScaleZ(_startScaleZ + _deltaZ * 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-12-18 17:47:20 +08:00
|
|
|
ScaleBy *scaleBy = new ScaleBy();
|
|
|
|
scaleBy->initWithDuration(duration, s);
|
|
|
|
scaleBy->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return scaleBy;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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-12-18 17:47:20 +08:00
|
|
|
ScaleBy *scaleBy = new ScaleBy();
|
2014-03-19 16:23:14 +08:00
|
|
|
scaleBy->initWithDuration(duration, sx, sy, 1.f);
|
|
|
|
scaleBy->autorelease();
|
|
|
|
|
|
|
|
return scaleBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScaleBy* ScaleBy::create(float duration, float sx, float sy, float sz)
|
|
|
|
{
|
|
|
|
ScaleBy *scaleBy = new ScaleBy();
|
|
|
|
scaleBy->initWithDuration(duration, sx, sy, sz);
|
2013-12-18 17:47:20 +08:00
|
|
|
scaleBy->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return scaleBy;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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();
|
2014-03-19 16:23:14 +08:00
|
|
|
a->initWithDuration(_duration, _endScaleX, _endScaleY, _endScaleZ);
|
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;
|
2014-03-19 16:23:14 +08:00
|
|
|
_deltaZ = _startScaleZ * _endScaleZ - _startScaleZ;
|
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
|
|
|
{
|
2014-03-19 16:23:14 +08:00
|
|
|
return ScaleBy::create(_duration, 1 / _endScaleX, 1 / _endScaleY, 1/ _endScaleZ);
|
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-12-18 17:47:20 +08:00
|
|
|
Blink *blink = new Blink();
|
|
|
|
blink->initWithDuration(duration, blinks);
|
|
|
|
blink->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return blink;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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-12-18 17:47:20 +08:00
|
|
|
FadeIn* action = new FadeIn();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-02-25 15:30:54 +08:00
|
|
|
action->initWithDuration(d,255.0f);
|
2013-12-18 17:47:20 +08:00
|
|
|
action->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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();
|
2014-02-25 15:30:54 +08:00
|
|
|
a->initWithDuration(_duration,255.0f);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2014-02-25 15:30:54 +08:00
|
|
|
void FadeIn::setReverseAction(cocos2d::FadeTo *ac)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-02-25 15:30:54 +08:00
|
|
|
_reverseAction = ac;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FadeTo* FadeIn::reverse() const
|
|
|
|
{
|
|
|
|
auto action = FadeOut::create(_duration);
|
|
|
|
action->setReverseAction(const_cast<FadeIn*>(this));
|
|
|
|
return action;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-02-25 15:30:54 +08:00
|
|
|
void FadeIn::startWithTarget(cocos2d::Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-02-25 15:30:54 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
|
|
|
|
if (nullptr != _reverseAction) {
|
|
|
|
this->_toOpacity = this->_reverseAction->_fromOpacity;
|
|
|
|
}else{
|
|
|
|
_toOpacity = 255.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target) {
|
|
|
|
_fromOpacity = target->getOpacity();
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-02-25 15:30:54 +08:00
|
|
|
|
|
|
|
|
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-12-18 17:47:20 +08:00
|
|
|
FadeOut* action = new FadeOut();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-02-25 15:30:54 +08:00
|
|
|
action->initWithDuration(d,0.0f);
|
2013-12-18 17:47:20 +08:00
|
|
|
action->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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();
|
2014-02-25 15:30:54 +08:00
|
|
|
a->initWithDuration(_duration,0.0f);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2014-02-25 15:30:54 +08:00
|
|
|
void FadeOut::startWithTarget(cocos2d::Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-02-25 15:30:54 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
|
|
|
|
if (nullptr != _reverseAction) {
|
|
|
|
_toOpacity = _reverseAction->_fromOpacity;
|
|
|
|
}else{
|
|
|
|
_toOpacity = 0.0f;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2014-02-25 15:30:54 +08:00
|
|
|
|
|
|
|
if (target) {
|
|
|
|
_fromOpacity = target->getOpacity();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FadeOut::setReverseAction(cocos2d::FadeTo *ac)
|
|
|
|
{
|
|
|
|
_reverseAction = ac;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-02-25 15:30:54 +08:00
|
|
|
|
|
|
|
FadeTo* FadeOut::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-02-25 15:30:54 +08:00
|
|
|
auto action = FadeIn::create(_duration);
|
|
|
|
action->setReverseAction(const_cast<FadeOut*>(this));
|
|
|
|
return action;
|
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-12-18 17:47:20 +08:00
|
|
|
FadeTo *fadeTo = new FadeTo();
|
|
|
|
fadeTo->initWithDuration(duration, opacity);
|
|
|
|
fadeTo->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return fadeTo;
|
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-12-06 18:07:16 +08:00
|
|
|
if (target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-06 18:07:16 +08:00
|
|
|
_fromOpacity = target->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-12-06 18:07:16 +08:00
|
|
|
if (_target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-06 18:07:16 +08:00
|
|
|
_target->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-12-18 17:47:20 +08:00
|
|
|
TintTo *tintTo = new TintTo();
|
|
|
|
tintTo->initWithDuration(duration, red, green, blue);
|
|
|
|
tintTo->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return tintTo;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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-12-06 18:07:16 +08:00
|
|
|
if (_target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-06 18:07:16 +08:00
|
|
|
_from = _target->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-12-06 18:07:16 +08:00
|
|
|
if (_target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-06 18:07:16 +08:00
|
|
|
_target->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-12-18 17:47:20 +08:00
|
|
|
TintBy *tintBy = new TintBy();
|
|
|
|
tintBy->initWithDuration(duration, deltaRed, deltaGreen, deltaBlue);
|
|
|
|
tintBy->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return tintBy;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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-12-06 18:07:16 +08:00
|
|
|
if (target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-06 18:07:16 +08:00
|
|
|
Color3B color = target->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-12-06 18:07:16 +08:00
|
|
|
if (_target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-06 18:07:16 +08:00
|
|
|
_target->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-12-18 17:47:20 +08:00
|
|
|
DelayTime* action = new DelayTime();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
action->initWithDuration(d);
|
|
|
|
action->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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-12-18 17:47:20 +08:00
|
|
|
ReverseTime* ReverseTime::create(FiniteTimeAction *action)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// casting to prevent warnings
|
2013-12-18 17:47:20 +08:00
|
|
|
ReverseTime *reverseTime = new ReverseTime();
|
|
|
|
reverseTime->initWithAction( action->clone() );
|
|
|
|
reverseTime->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return reverseTime;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool ReverseTime::initWithAction(FiniteTimeAction *action)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT(action != nullptr, "");
|
|
|
|
CCASSERT(action != _other, "");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
if (ActionInterval::initWithDuration(action->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-12-18 17:47:20 +08:00
|
|
|
_other = action;
|
|
|
|
action->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
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-12-18 17:47:20 +08:00
|
|
|
ReverseTime::ReverseTime() : _other(nullptr)
|
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-12-18 17:47:20 +08:00
|
|
|
Animate* Animate::create(Animation *animation)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
Animate *animate = new Animate();
|
|
|
|
animate->initWithAnimation(animation);
|
|
|
|
animate->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return animate;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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)
|
2013-12-18 17:47:20 +08:00
|
|
|
, _origFrame(nullptr)
|
2013-07-20 04:16:38 +08:00
|
|
|
, _executedLoops(0)
|
2013-12-18 17:47:20 +08:00
|
|
|
, _animation(nullptr)
|
2013-07-20 04:16:38 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Animate::~Animate()
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(_animation);
|
|
|
|
CC_SAFE_RELEASE(_origFrame);
|
|
|
|
CC_SAFE_DELETE(_splitTimes);
|
|
|
|
}
|
|
|
|
|
2013-11-28 16:02:03 +08:00
|
|
|
bool Animate::initWithAnimation(Animation* animation)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CCASSERT( animation!=nullptr, "Animate: argument Animation must be non-nullptr");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-11-28 16:02:03 +08:00
|
|
|
float singleDuration = animation->getDuration();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-11-28 16:02:03 +08:00
|
|
|
if ( ActionInterval::initWithDuration(singleDuration * animation->getLoops() ) )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_nextFrame = 0;
|
2013-11-28 16:02:03 +08:00
|
|
|
setAnimation(animation);
|
2013-12-18 17:47:20 +08:00
|
|
|
_origFrame = nullptr;
|
2013-06-15 14:03:30 +08:00
|
|
|
_executedLoops = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-05 10:35:10 +08:00
|
|
|
_splitTimes->reserve(animation->getFrames().size());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
float accumUnitsOfTime = 0;
|
2013-11-28 16:02:03 +08:00
|
|
|
float newUnitOfTimeValue = singleDuration / animation->getTotalDelayUnits();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-11-28 16:02:03 +08:00
|
|
|
auto frames = animation->getFrames();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-11-28 16:02:03 +08:00
|
|
|
for (auto& frame : frames)
|
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);
|
2013-12-18 17:47:20 +08:00
|
|
|
Sprite *sprite = 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-12-25 16:06:39 +08:00
|
|
|
_origFrame = sprite->getSpriteFrame();
|
2013-06-15 14:03:30 +08:00
|
|
|
_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-12-25 16:06:39 +08:00
|
|
|
static_cast<Sprite*>(_target)->setSpriteFrame(_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-11-28 16:02:03 +08:00
|
|
|
auto frames = _animation->getFrames();
|
2013-12-05 17:19:01 +08:00
|
|
|
auto numberOfFrames = frames.size();
|
2013-12-18 17:47:20 +08:00
|
|
|
SpriteFrame *frameToDisplay = nullptr;
|
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-12-05 10:35:10 +08:00
|
|
|
AnimationFrame* frame = frames.at(i);
|
2012-04-19 14:35:52 +08:00
|
|
|
frameToDisplay = frame->getSpriteFrame();
|
2013-12-25 16:06:39 +08:00
|
|
|
static_cast<Sprite*>(_target)->setSpriteFrame(frameToDisplay);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-04 17:46:57 +08:00
|
|
|
const ValueMap& dict = frame->getUserInfo();
|
2013-12-03 14:47:35 +08:00
|
|
|
if ( !dict.empty() )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
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-11-28 16:02:03 +08:00
|
|
|
auto oldArray = _animation->getFrames();
|
2013-12-05 10:35:10 +08:00
|
|
|
Vector<AnimationFrame*> newArray(oldArray.size());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-05 10:35:10 +08:00
|
|
|
if (oldArray.size() > 0)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-29 11:36:42 +08:00
|
|
|
for (auto iter = oldArray.crbegin(); iter != oldArray.crend(); ++iter)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-28 16:02:03 +08:00
|
|
|
AnimationFrame* animFrame = *iter;
|
|
|
|
if (!animFrame)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-05 10:35:10 +08:00
|
|
|
newArray.pushBack(animFrame->clone());
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-28 16:02:03 +08:00
|
|
|
Animation *newAnim = Animation::create(newArray, _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-12-18 17:47:20 +08:00
|
|
|
: _action(nullptr)
|
|
|
|
, _forcedTarget(nullptr)
|
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-12-18 17:47:20 +08:00
|
|
|
TargetedAction* TargetedAction::create(Node* target, FiniteTimeAction* action)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
TargetedAction* p = new TargetedAction();
|
2013-12-18 17:47:20 +08:00
|
|
|
p->initWithTarget(target, action);
|
2012-04-19 14:35:52 +08:00
|
|
|
p->autorelease();
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool TargetedAction::initWithTarget(Node* target, FiniteTimeAction* action)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if(ActionInterval::initWithDuration(action->getDuration()))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
CC_SAFE_RETAIN(target);
|
|
|
|
_forcedTarget = target;
|
2013-12-18 17:47:20 +08:00
|
|
|
CC_SAFE_RETAIN(action);
|
|
|
|
_action = action;
|
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
|