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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCActionInterval.h"
|
2014-09-10 07:50:02 +08:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCSprite.h"
|
|
|
|
#include "2d/CCNode.h"
|
2014-08-26 18:19:28 +08:00
|
|
|
#include "2d/CCSpriteFrame.h"
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCActionInstant.h"
|
2014-05-13 17:08:30 +08:00
|
|
|
#include "base/CCDirector.h"
|
|
|
|
#include "base/CCEventCustom.h"
|
2014-08-26 18:19:28 +08:00
|
|
|
#include "base/CCEventDispatcher.h"
|
2014-09-10 07:50:02 +08:00
|
|
|
#include "platform/CCStdC.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
ExtraAction* ret = new (std::nothrow) ExtraAction();
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
}
|
2014-05-28 17:41:34 +08:00
|
|
|
ExtraAction* ExtraAction::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) ExtraAction();
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
2012-12-10 12:02:24 +08:00
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
ExtraAction* ExtraAction::reverse() 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;
|
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
bool ActionInterval::isDone() 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
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
float ActionInterval::getAmplitudeRate()
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
Sequence *sequence = new (std::nothrow) Sequence();
|
2013-11-22 09:06:06 +08:00
|
|
|
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-04-20 00:25:54 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
2014-03-25 06:09:24 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
Sequence* Sequence::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) Sequence();
|
2013-07-08 23:05:47 +08:00
|
|
|
a->initWithTwoActions(_actions[0]->clone(), _actions[1]->clone() );
|
2015-01-08 10:22:45 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2015-01-08 10:22:45 +08:00
|
|
|
else if(found==0 && _last==1 )
|
|
|
|
{
|
|
|
|
// Reverse mode ?
|
|
|
|
// FIXME: 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.
|
|
|
|
_actions[1]->update(0);
|
|
|
|
_actions[1]->stop();
|
|
|
|
}
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
Repeat* repeat = new (std::nothrow) Repeat();
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) Repeat();
|
|
|
|
a->initWithAction( _innerAction->clone(), _times );
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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);
|
2014-05-22 14:59:47 +08:00
|
|
|
_nextDt = _innerAction->getDuration()/_duration * (_total+1);
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
RepeatForever *ret = new (std::nothrow) RepeatForever();
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
RepeatForever *RepeatForever::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) RepeatForever();
|
|
|
|
a->initWithAction(_innerAction->clone());
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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();
|
2014-06-16 18:21:47 +08:00
|
|
|
if (diff > _innerAction->getDuration())
|
|
|
|
diff = fmodf(diff, _innerAction->getDuration());
|
2013-06-15 14:03:30 +08:00
|
|
|
_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-04-20 00:25:54 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
2014-03-25 06:09:24 +08:00
|
|
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
Spawn *spawn = new (std::nothrow) Spawn();
|
2013-11-22 09:06:06 +08:00
|
|
|
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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) Spawn();
|
2013-06-19 06:06:53 +08:00
|
|
|
a->initWithTwoActions(_one->clone(), _two->clone());
|
2013-06-14 08:25:14 +08:00
|
|
|
|
2015-01-08 10:22:45 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-08-01 04:37:21 +08:00
|
|
|
RotateTo* RotateTo::create(float duration, float dstAngle)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
RotateTo* rotateTo = new (std::nothrow) RotateTo();
|
2014-08-01 04:37:21 +08:00
|
|
|
rotateTo->initWithDuration(duration, dstAngle, dstAngle);
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-08-01 04:37:21 +08:00
|
|
|
RotateTo* RotateTo::create(float duration, float dstAngleX, float dstAngleY)
|
2014-07-31 03:01:18 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
RotateTo* rotateTo = new (std::nothrow) RotateTo();
|
2014-08-01 04:37:21 +08:00
|
|
|
rotateTo->initWithDuration(duration, dstAngleX, dstAngleY);
|
2014-07-31 03:01:18 +08:00
|
|
|
rotateTo->autorelease();
|
|
|
|
|
|
|
|
return rotateTo;
|
|
|
|
}
|
|
|
|
|
2014-08-01 04:37:21 +08:00
|
|
|
RotateTo* RotateTo::create(float duration, const Vec3& dstAngle3D)
|
2014-07-31 03:01:18 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
RotateTo* rotateTo = new (std::nothrow) RotateTo();
|
2014-08-01 04:37:21 +08:00
|
|
|
rotateTo->initWithDuration(duration, dstAngle3D);
|
2014-07-31 03:01:18 +08:00
|
|
|
rotateTo->autorelease();
|
|
|
|
|
|
|
|
return rotateTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
RotateTo::RotateTo()
|
|
|
|
: _is3D(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-08-01 04:37:21 +08:00
|
|
|
bool RotateTo::initWithDuration(float duration, float dstAngleX, float dstAngleY)
|
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-08-01 04:37:21 +08:00
|
|
|
_dstAngle.x = dstAngleX;
|
|
|
|
_dstAngle.y = dstAngleY;
|
2014-07-31 03:01:18 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-15 17:16:51 +08:00
|
|
|
|
2014-07-31 03:01:18 +08:00
|
|
|
return false;
|
2012-11-15 17:16:51 +08:00
|
|
|
}
|
|
|
|
|
2014-08-01 04:37:21 +08:00
|
|
|
bool RotateTo::initWithDuration(float duration, const Vec3& dstAngle3D)
|
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-08-01 04:37:21 +08:00
|
|
|
_dstAngle = dstAngle3D;
|
2014-07-31 03:01:18 +08:00
|
|
|
_is3D = true;
|
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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) RotateTo();
|
2014-07-31 03:01:18 +08:00
|
|
|
if(_is3D)
|
2015-01-08 10:22:45 +08:00
|
|
|
a->initWithDuration(_duration, _dstAngle);
|
2014-07-31 03:01:18 +08:00
|
|
|
else
|
2014-08-01 04:37:21 +08:00
|
|
|
a->initWithDuration(_duration, _dstAngle.x, _dstAngle.y);
|
2015-01-08 10:22:45 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2014-07-31 03:01:18 +08:00
|
|
|
void RotateTo::calculateAngles(float &startAngle, float &diffAngle, float dstAngle)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-07-31 03:01:18 +08:00
|
|
|
if (startAngle > 0)
|
2013-02-27 09:38:30 +08:00
|
|
|
{
|
2014-07-31 03:01:18 +08:00
|
|
|
startAngle = fmodf(startAngle, 360.0f);
|
2013-02-27 09:38:30 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-31 03:01:18 +08:00
|
|
|
startAngle = fmodf(startAngle, -360.0f);
|
2012-12-26 18:59:31 +08:00
|
|
|
}
|
|
|
|
|
2014-07-31 03:01:18 +08:00
|
|
|
diffAngle = dstAngle - startAngle;
|
|
|
|
if (diffAngle > 180)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2014-07-31 03:01:18 +08:00
|
|
|
diffAngle -= 360;
|
2012-11-15 17:16:51 +08:00
|
|
|
}
|
2014-07-31 03:01:18 +08:00
|
|
|
if (diffAngle < -180)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2014-07-31 03:01:18 +08:00
|
|
|
diffAngle += 360;
|
2012-11-15 17:16:51 +08:00
|
|
|
}
|
2014-07-31 03:01:18 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-07-31 03:01:18 +08:00
|
|
|
void RotateTo::startWithTarget(Node *target)
|
|
|
|
{
|
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
|
|
|
|
if (_is3D)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-08-01 04:37:21 +08:00
|
|
|
_startAngle = _target->getRotation3D();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-01 04:37:21 +08:00
|
|
|
_startAngle.x = _target->getRotationSkewX();
|
|
|
|
_startAngle.y = _target->getRotationSkewY();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2014-08-01 04:37:21 +08:00
|
|
|
|
|
|
|
calculateAngles(_startAngle.x, _diffAngle.x, _dstAngle.x);
|
|
|
|
calculateAngles(_startAngle.y, _diffAngle.y, _dstAngle.y);
|
|
|
|
calculateAngles(_startAngle.z, _diffAngle.z, _dstAngle.z);
|
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-07-31 03:01:18 +08:00
|
|
|
if(_is3D)
|
2014-06-20 18:40:21 +08:00
|
|
|
{
|
2014-07-31 03:01:18 +08:00
|
|
|
_target->setRotation3D(Vec3(
|
2014-08-01 04:37:21 +08:00
|
|
|
_startAngle.x + _diffAngle.x * time,
|
|
|
|
_startAngle.y + _diffAngle.y * time,
|
|
|
|
_startAngle.z + _diffAngle.z * time
|
2014-07-31 03:01:18 +08:00
|
|
|
));
|
2014-06-20 18:40:21 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-31 03:01:18 +08:00
|
|
|
#if CC_USE_PHYSICS
|
2014-08-01 04:37:21 +08:00
|
|
|
if (_startAngle.x == _startAngle.y && _diffAngle.x == _diffAngle.y)
|
2014-06-23 13:55:52 +08:00
|
|
|
{
|
2014-08-01 04:37:21 +08:00
|
|
|
_target->setRotation(_startAngle.x + _diffAngle.x * time);
|
2014-06-23 13:55:52 +08:00
|
|
|
}
|
2014-07-31 03:01:18 +08:00
|
|
|
else
|
|
|
|
{
|
2014-08-01 04:37:21 +08:00
|
|
|
_target->setRotationSkewX(_startAngle.x + _diffAngle.x * time);
|
|
|
|
_target->setRotationSkewY(_startAngle.y + _diffAngle.y * time);
|
2014-07-31 03:01:18 +08:00
|
|
|
}
|
|
|
|
#else
|
2014-08-01 04:37:21 +08:00
|
|
|
_target->setRotationSkewX(_startAngle.x + _diffAngle.x * time);
|
|
|
|
_target->setRotationSkewY(_startAngle.y + _diffAngle.y * time);
|
2014-06-20 18:40:21 +08:00
|
|
|
#endif // CC_USE_PHYSICS
|
2014-07-31 03:01:18 +08:00
|
|
|
}
|
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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
CCASSERT(false, "RotateTo doesn't support the 'reverse' method");
|
|
|
|
return nullptr;
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
RotateBy *rotateBy = new (std::nothrow) RotateBy();
|
2013-12-18 17:47:20 +08:00
|
|
|
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)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
RotateBy *rotateBy = new (std::nothrow) RotateBy();
|
2014-02-23 11:16:42 +08:00
|
|
|
rotateBy->initWithDuration(duration, deltaAngleX, deltaAngleY);
|
|
|
|
rotateBy->autorelease();
|
|
|
|
|
|
|
|
return rotateBy;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
RotateBy* RotateBy::create(float duration, const Vec3& deltaAngle3D)
|
2014-02-23 11:16:42 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
RotateBy *rotateBy = new (std::nothrow) RotateBy();
|
2014-02-23 11:16:42 +08:00
|
|
|
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-08-01 05:28:33 +08:00
|
|
|
_deltaAngle.x = _deltaAngle.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))
|
|
|
|
{
|
2014-08-01 05:28:33 +08:00
|
|
|
_deltaAngle.x = deltaAngleX;
|
|
|
|
_deltaAngle.y = deltaAngleY;
|
2014-02-23 11:16:42 +08:00
|
|
|
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-05-15 01:07:09 +08:00
|
|
|
bool RotateBy::initWithDuration(float duration, const Vec3& 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-08-01 05:28:33 +08:00
|
|
|
_deltaAngle = deltaAngle3D;
|
2014-02-23 11:16:42 +08:00
|
|
|
_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
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
RotateBy* RotateBy::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) RotateBy();
|
2014-02-23 11:16:42 +08:00
|
|
|
if(_is3D)
|
2014-08-01 05:28:33 +08:00
|
|
|
a->initWithDuration(_duration, _deltaAngle);
|
2014-02-23 11:16:42 +08:00
|
|
|
else
|
2014-08-01 05:28:33 +08:00
|
|
|
a->initWithDuration(_duration, _deltaAngle.x, _deltaAngle.y);
|
2015-01-08 10:22:45 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2014-08-01 05:28:33 +08:00
|
|
|
_startAngle = target->getRotation3D();
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-01 05:28:33 +08:00
|
|
|
_startAngle.x = target->getRotationSkewX();
|
|
|
|
_startAngle.y = target->getRotationSkewY();
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
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
|
|
|
{
|
2014-08-30 03:54:24 +08:00
|
|
|
// FIXME: 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-05-15 01:07:09 +08:00
|
|
|
Vec3 v;
|
2014-08-01 05:28:33 +08:00
|
|
|
v.x = _startAngle.x + _deltaAngle.x * time;
|
|
|
|
v.y = _startAngle.y + _deltaAngle.y * time;
|
|
|
|
v.z = _startAngle.z + _deltaAngle.z * time;
|
2014-02-23 11:16:42 +08:00
|
|
|
_target->setRotation3D(v);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-20 18:40:21 +08:00
|
|
|
#if CC_USE_PHYSICS
|
2014-08-01 05:28:33 +08:00
|
|
|
if (_startAngle.x == _startAngle.y && _deltaAngle.x == _deltaAngle.y)
|
2014-06-20 18:40:21 +08:00
|
|
|
{
|
2014-08-01 05:28:33 +08:00
|
|
|
_target->setRotation(_startAngle.x + _deltaAngle.x * time);
|
2014-06-20 18:40:21 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-01 05:28:33 +08:00
|
|
|
_target->setRotationSkewX(_startAngle.x + _deltaAngle.x * time);
|
|
|
|
_target->setRotationSkewY(_startAngle.y + _deltaAngle.y * time);
|
2014-06-20 18:40:21 +08:00
|
|
|
}
|
2014-06-23 13:55:52 +08:00
|
|
|
#else
|
2014-08-01 05:28:33 +08:00
|
|
|
_target->setRotationSkewX(_startAngle.x + _deltaAngle.x * time);
|
|
|
|
_target->setRotationSkewY(_startAngle.y + _deltaAngle.y * time);
|
2014-06-20 18:40:21 +08:00
|
|
|
#endif // CC_USE_PHYSICS
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
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-05-15 01:07:09 +08:00
|
|
|
Vec3 v;
|
2014-08-01 05:28:33 +08:00
|
|
|
v.x = - _deltaAngle.x;
|
|
|
|
v.y = - _deltaAngle.y;
|
|
|
|
v.z = - _deltaAngle.z;
|
2014-02-23 11:16:42 +08:00
|
|
|
return RotateBy::create(_duration, v);
|
|
|
|
}
|
2014-08-01 05:28:33 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return RotateBy::create(_duration, -_deltaAngle.x, -_deltaAngle.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-05-15 01:07:09 +08:00
|
|
|
MoveBy* MoveBy::create(float duration, const Vec2& deltaPosition)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-12-22 14:34:35 +08:00
|
|
|
return MoveBy::create(duration, Vec3(deltaPosition.x, deltaPosition.y, 0));
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-12-22 14:34:35 +08:00
|
|
|
MoveBy* MoveBy::create(float duration, const Vec3 &deltaPosition)
|
|
|
|
{
|
|
|
|
MoveBy *ret = new (std::nothrow) MoveBy();
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (ret->initWithDuration(duration, deltaPosition))
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete ret;
|
|
|
|
ret = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
bool MoveBy::initWithDuration(float duration, const Vec2& deltaPosition)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-12-22 14:34:35 +08:00
|
|
|
return MoveBy::initWithDuration(duration, Vec3(deltaPosition.x, deltaPosition.y, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MoveBy::initWithDuration(float duration, const Vec3& deltaPosition)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
|
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;
|
2014-12-22 14:34:35 +08:00
|
|
|
_is3D = true;
|
|
|
|
ret = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2014-12-22 14:34:35 +08:00
|
|
|
|
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
MoveBy* MoveBy::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) MoveBy();
|
2013-06-15 14:03:30 +08:00
|
|
|
a->initWithDuration(_duration, _positionDelta);
|
2015-01-08 10:22:45 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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);
|
2014-12-22 14:34:35 +08:00
|
|
|
_previousPosition = _startPosition = target->getPosition3D();
|
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-12-22 14:34:35 +08:00
|
|
|
return MoveBy::create(_duration, -_positionDelta);
|
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-12-22 14:34:35 +08:00
|
|
|
Vec3 currentPos = _target->getPosition3D();
|
|
|
|
Vec3 diff = currentPos - _previousPosition;
|
2013-07-11 16:38:58 +08:00
|
|
|
_startPosition = _startPosition + diff;
|
2014-12-22 14:34:35 +08:00
|
|
|
Vec3 newPos = _startPosition + (_positionDelta * t);
|
|
|
|
_target->setPosition3D(newPos);
|
2013-06-15 14:03:30 +08:00
|
|
|
_previousPosition = newPos;
|
2013-02-27 09:38:30 +08:00
|
|
|
#else
|
2014-12-22 14:34:35 +08:00
|
|
|
_target->setPosition3D(_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-05-15 01:07:09 +08:00
|
|
|
MoveTo* MoveTo::create(float duration, const Vec2& position)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-12-22 14:34:35 +08:00
|
|
|
return MoveTo::create(duration, Vec3(position.x, position.y, 0));
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-12-22 14:34:35 +08:00
|
|
|
MoveTo* MoveTo::create(float duration, const Vec3& position)
|
|
|
|
{
|
|
|
|
MoveTo *ret = new (std::nothrow) MoveTo();
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (ret->initWithDuration(duration, position))
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete ret;
|
|
|
|
ret = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
bool MoveTo::initWithDuration(float duration, const Vec2& position)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-12-22 14:34:35 +08:00
|
|
|
return initWithDuration(duration, Vec3(position.x, position.y, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MoveTo::initWithDuration(float duration, const Vec3& position)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
|
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;
|
2014-12-22 14:34:35 +08:00
|
|
|
ret = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2014-12-22 14:34:35 +08:00
|
|
|
|
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
MoveTo* MoveTo::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) MoveTo();
|
2013-06-15 14:03:30 +08:00
|
|
|
a->initWithDuration(_duration, _endPosition);
|
2015-01-08 10:22:45 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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);
|
2014-12-22 14:34:35 +08:00
|
|
|
_positionDelta = _endPosition - target->getPosition3D();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2015-03-10 13:50:53 +08:00
|
|
|
MoveTo* MoveTo::reverse() const
|
|
|
|
{
|
|
|
|
CCASSERT(false, "reverse() not supported in MoveTo");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
SkewTo *skewTo = new (std::nothrow) SkewTo();
|
2013-12-18 17:47:20 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
SkewTo* SkewTo::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) SkewTo();
|
|
|
|
a->initWithDuration(_duration, _endSkewX, _endSkewY);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
SkewTo* SkewTo::reverse() const
|
2013-06-19 06:06:53 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
CCASSERT(false, "reverse() not supported in SkewTo");
|
|
|
|
return nullptr;
|
2013-06-19 06:06:53 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
SkewBy *skewBy = new (std::nothrow) SkewBy();
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) SkewBy();
|
|
|
|
a->initWithDuration(_duration, _skewX, _skewY);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
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-05-15 01:07:09 +08:00
|
|
|
JumpBy* JumpBy::create(float duration, const Vec2& position, float height, int jumps)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
JumpBy *jumpBy = new (std::nothrow) JumpBy();
|
2013-12-18 17:47:20 +08:00
|
|
|
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-05-15 01:07:09 +08:00
|
|
|
bool JumpBy::initWithDuration(float duration, const Vec2& 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;
|
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
JumpBy* JumpBy::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) JumpBy();
|
|
|
|
a->initWithDuration(_duration, _delta, _height, _jumps);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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-05-15 01:07:09 +08:00
|
|
|
Vec2 currentPos = _target->getPosition();
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 diff = currentPos - _previousPos;
|
2013-07-11 16:38:58 +08:00
|
|
|
_startPosition = diff + _startPosition;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 newPos = _startPosition + Vec2(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-05-15 01:07:09 +08:00
|
|
|
_target->setPosition(_startPosition + Vec2(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-05-15 01:07:09 +08:00
|
|
|
return JumpBy::create(_duration, Vec2(-_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-05-15 01:07:09 +08:00
|
|
|
JumpTo* JumpTo::create(float duration, const Vec2& position, float height, int jumps)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
JumpTo *jumpTo = new (std::nothrow) JumpTo();
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-01-03 00:13:57 +08:00
|
|
|
bool JumpTo::initWithDuration(float duration, const Vec2& position, float height, int jumps)
|
|
|
|
{
|
|
|
|
CCASSERT(jumps>=0, "Number of jumps must be >= 0");
|
|
|
|
|
|
|
|
if (ActionInterval::initWithDuration(duration) && jumps>=0)
|
|
|
|
{
|
|
|
|
_endPosition = position;
|
|
|
|
_height = height;
|
|
|
|
_jumps = jumps;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
JumpTo* JumpTo::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) JumpTo();
|
2013-06-15 14:03:30 +08:00
|
|
|
a->initWithDuration(_duration, _delta, _height, _jumps);
|
2015-01-08 10:22:45 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
JumpTo* JumpTo::reverse() const
|
2013-06-19 06:06:53 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
CCASSERT(false, "reverse() not supported in JumpTo");
|
|
|
|
return nullptr;
|
2013-06-19 06:06:53 +08:00
|
|
|
}
|
|
|
|
|
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);
|
2015-04-20 01:40:52 +08:00
|
|
|
_delta.set(_endPosition.x - _startPosition.x, _endPosition.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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
BezierBy *bezierBy = new (std::nothrow) BezierBy();
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
BezierBy* BezierBy::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) BezierBy();
|
|
|
|
a->initWithDuration(_duration, _config);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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-05-15 01:07:09 +08:00
|
|
|
Vec2 currentPos = _target->getPosition();
|
|
|
|
Vec2 diff = currentPos - _previousPosition;
|
2013-07-11 16:38:58 +08:00
|
|
|
_startPosition = _startPosition + diff;
|
2013-02-27 09:38:30 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 newPos = _startPosition + Vec2(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-05-15 01:07:09 +08:00
|
|
|
_target->setPosition( _startPosition + Vec2(x,y));
|
2013-02-27 09:38:30 +08:00
|
|
|
#endif // !CC_ENABLE_STACKABLE_ACTIONS
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
BezierBy* BezierBy::reverse() 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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
BezierTo *bezierTo = new (std::nothrow) BezierTo();
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
BezierTo* BezierTo::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) BezierTo();
|
|
|
|
a->initWithDuration(_duration, _toConfig);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
CCASSERT(false, "CCBezierTo doesn't support the 'reverse' method");
|
|
|
|
return nullptr;
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
ScaleTo *scaleTo = new (std::nothrow) ScaleTo();
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
ScaleTo *scaleTo = new (std::nothrow) ScaleTo();
|
2013-12-18 17:47:20 +08:00
|
|
|
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)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
ScaleTo *scaleTo = new (std::nothrow) ScaleTo();
|
2014-03-19 16:23:14 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
ScaleTo* ScaleTo::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) ScaleTo();
|
|
|
|
a->initWithDuration(_duration, _endScaleX, _endScaleY, _endScaleZ);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ScaleTo* ScaleTo::reverse() const
|
2013-06-19 06:06:53 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
CCASSERT(false, "reverse() not supported in ScaleTo");
|
|
|
|
return nullptr;
|
2013-06-19 06:06:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
ScaleBy *scaleBy = new (std::nothrow) ScaleBy();
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
ScaleBy *scaleBy = new (std::nothrow) 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)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
ScaleBy *scaleBy = new (std::nothrow) ScaleBy();
|
2014-03-19 16:23:14 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
ScaleBy* ScaleBy::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) ScaleBy();
|
2014-03-19 16:23:14 +08:00
|
|
|
a->initWithDuration(_duration, _endScaleX, _endScaleY, _endScaleZ);
|
2015-01-08 10:22:45 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
Blink *blink = new (std::nothrow) Blink();
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) Blink();
|
|
|
|
a->initWithDuration(_duration, _times);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
FadeIn* action = new (std::nothrow) 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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) FadeIn();
|
2014-02-25 15:30:54 +08:00
|
|
|
a->initWithDuration(_duration,255.0f);
|
2015-01-08 10:22:45 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
FadeOut* action = new (std::nothrow) 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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) FadeOut();
|
2014-02-25 15:30:54 +08:00
|
|
|
a->initWithDuration(_duration,0.0f);
|
2015-01-08 10:22:45 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
FadeTo *fadeTo = new (std::nothrow) FadeTo();
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) FadeTo();
|
|
|
|
a->initWithDuration(_duration, _toOpacity);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeTo* FadeTo::reverse() const
|
2013-06-19 06:06:53 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
CCASSERT(false, "reverse() not supported in FadeTo");
|
|
|
|
return nullptr;
|
2013-06-19 06:06:53 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
TintTo *tintTo = new (std::nothrow) TintTo();
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-01-14 17:04:23 +08:00
|
|
|
TintTo* TintTo::create(float duration, const Color3B& color)
|
|
|
|
{
|
|
|
|
return create(duration, color.r, color.g, color.b);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) TintTo();
|
|
|
|
a->initWithDuration(_duration, _to.r, _to.g, _to.b);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TintTo* TintTo::reverse() const
|
2013-06-19 06:06:53 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
CCASSERT(false, "reverse() not supported in TintTo");
|
|
|
|
return nullptr;
|
2013-06-19 06:06:53 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
TintBy *tintBy = new (std::nothrow) TintBy();
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) TintBy();
|
|
|
|
a->initWithDuration(_duration, (GLubyte)_deltaR, (GLubyte)_deltaG, (GLubyte)_deltaB);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
DelayTime* action = new (std::nothrow) 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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) DelayTime();
|
2013-07-10 14:16:42 +08:00
|
|
|
a->initWithDuration(_duration);
|
2015-01-08 10:22:45 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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
|
2014-08-28 07:31:57 +08:00
|
|
|
ReverseTime *reverseTime = new (std::nothrow) ReverseTime();
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) ReverseTime();
|
|
|
|
a->initWithAction( _other->clone() );
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
ReverseTime::ReverseTime() : _other(nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
ReverseTime::~ReverseTime()
|
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
|
|
|
{
|
2014-08-30 03:54:24 +08:00
|
|
|
// FIXME: 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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
Animate *animate = new (std::nothrow) Animate();
|
2013-12-18 17:47:20 +08:00
|
|
|
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)
|
2014-05-13 17:29:05 +08:00
|
|
|
, _frameDisplayedEvent(nullptr)
|
2013-07-20 04:16:38 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Animate::~Animate()
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(_animation);
|
|
|
|
CC_SAFE_RELEASE(_origFrame);
|
|
|
|
CC_SAFE_DELETE(_splitTimes);
|
2014-05-13 17:29:05 +08:00
|
|
|
CC_SAFE_RELEASE(_frameDisplayedEvent);
|
2013-07-20 04:16:38 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-12-21 00:22:23 +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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) Animate();
|
|
|
|
a->initWithAnimation(_animation->clone());
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
void Animate::stop()
|
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);
|
|
|
|
}
|
|
|
|
|
2014-12-21 00:22:23 +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
|
|
|
{
|
2014-05-13 17:29:05 +08:00
|
|
|
if (_frameDisplayedEvent == nullptr)
|
2014-08-28 07:31:57 +08:00
|
|
|
_frameDisplayedEvent = new (std::nothrow) EventCustom(AnimationFrameDisplayedNotification);
|
2014-05-13 17:29:05 +08:00
|
|
|
|
|
|
|
_frameDisplayedEventInfo.target = _target;
|
|
|
|
_frameDisplayedEventInfo.userInfo = &dict;
|
|
|
|
_frameDisplayedEvent->setUserData(&_frameDisplayedEventInfo);
|
|
|
|
Director::getInstance()->getEventDispatcher()->dispatchEvent(_frameDisplayedEvent);
|
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
|
|
|
{
|
2014-12-21 00:42:55 +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
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
TargetedAction* p = new (std::nothrow) 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
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) TargetedAction();
|
2013-06-15 14:03:30 +08:00
|
|
|
// win32 : use the _other's copy object.
|
2015-01-08 10:22:45 +08:00
|
|
|
a->initWithTarget(_forcedTarget, _action->clone());
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
TargetedAction* TargetedAction::reverse() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// just reverse the internal action
|
|
|
|
auto a = new (std::nothrow) 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
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
void TargetedAction::stop()
|
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
|