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.
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
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"
|
2015-08-27 17:55:38 +08:00
|
|
|
#include "base/CCScriptSupport.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;
|
2017-06-08 17:07:43 +08:00
|
|
|
virtual ExtraAction* reverse() 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
|
|
|
}
|
2016-04-08 13:40:36 +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
|
2016-04-08 13:40:36 +08:00
|
|
|
return ExtraAction::create();
|
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();
|
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ExtraAction::update(float /*time*/)
|
2012-12-10 14:11:42 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ExtraAction::step(float /*dt*/)
|
2012-12-10 14:11:42 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_elapsed = 0;
|
|
|
|
_firstTick = true;
|
2017-03-22 14:17:49 +08:00
|
|
|
_done = false;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-27 17:55:38 +08:00
|
|
|
bool ActionInterval::sendUpdateEventToScript(float dt, Action *actionObject)
|
|
|
|
{
|
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
|
|
|
if (_scriptType == kScriptTypeJavascript)
|
|
|
|
{
|
|
|
|
if (ScriptEngineManager::sendActionEventToJS(actionObject, kActionUpdate, (void *)&dt))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
bool ActionInterval::isDone() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2017-03-22 14:17:49 +08:00
|
|
|
return _done;
|
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
|
|
|
|
2015-08-27 17:55:38 +08:00
|
|
|
|
2018-01-02 10:35:54 +08:00
|
|
|
float updateDt = std::max(0.0f, // needed for rewind. elapsed could be negative
|
|
|
|
std::min(1.0f, _elapsed / _duration)
|
|
|
|
);
|
2015-08-27 17:55:38 +08:00
|
|
|
|
|
|
|
if (sendUpdateEventToScript(updateDt, this)) return;
|
|
|
|
|
|
|
|
this->update(updateDt);
|
2017-03-22 14:17:49 +08:00
|
|
|
|
|
|
|
_done = _elapsed >= _duration;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ActionInterval::setAmplitudeRate(float /*amp*/)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// Abstract class needs implementation
|
2015-07-14 15:28:36 +08:00
|
|
|
CCASSERT(0, "Subclass should implement this method!");
|
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
|
2015-07-14 15:28:36 +08:00
|
|
|
CCASSERT(0, "Subclass should implement this method!");
|
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;
|
2017-03-22 14:17:49 +08:00
|
|
|
_done = false;
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (sequence && sequence->initWithTwoActions(actionOne, actionTwo))
|
|
|
|
{
|
|
|
|
sequence->autorelease();
|
|
|
|
return sequence;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete sequence;
|
|
|
|
return nullptr;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2015-05-09 00:19:13 +08:00
|
|
|
#if (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
|
|
|
{
|
2015-12-04 04:16:21 +08:00
|
|
|
Sequence* seq = new (std::nothrow) Sequence;
|
2016-04-08 13:40:36 +08:00
|
|
|
|
2015-12-04 04:16:21 +08:00
|
|
|
if (seq && seq->init(arrayOfActions))
|
2016-04-08 13:40:36 +08:00
|
|
|
{
|
2015-12-04 04:16:21 +08:00
|
|
|
seq->autorelease();
|
2016-04-08 13:40:36 +08:00
|
|
|
return seq;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete seq;
|
|
|
|
return nullptr;
|
2015-12-04 04:16:21 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-12-04 04:16:21 +08:00
|
|
|
bool Sequence::init(const Vector<FiniteTimeAction*>& arrayOfActions)
|
|
|
|
{
|
|
|
|
auto count = arrayOfActions.size();
|
|
|
|
if (count == 0)
|
2016-04-08 13:40:36 +08:00
|
|
|
return false;
|
2015-12-04 04:16:21 +08:00
|
|
|
|
|
|
|
if (count == 1)
|
|
|
|
return initWithTwoActions(arrayOfActions.at(0), ExtraAction::create());
|
|
|
|
|
|
|
|
// else size > 1
|
|
|
|
auto prev = arrayOfActions.at(0);
|
|
|
|
for (int i = 1; i < count-1; ++i)
|
|
|
|
{
|
|
|
|
prev = createWithTwoActions(prev, arrayOfActions.at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return initWithTwoActions(prev, arrayOfActions.at(count-1));
|
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
|
|
|
{
|
2015-07-14 15:28:36 +08:00
|
|
|
CCASSERT(actionOne != nullptr, "actionOne can't be nullptr!");
|
|
|
|
CCASSERT(actionTwo != nullptr, "actionTwo can't be nullptr!");
|
2016-04-08 13:40:36 +08:00
|
|
|
if (actionOne == nullptr || actionTwo == nullptr)
|
|
|
|
{
|
|
|
|
log("Sequence::initWithTwoActions error: action is nullptr!!");
|
|
|
|
return false;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-08 14:52:36 +08:00
|
|
|
bool Sequence::isDone() const
|
|
|
|
{
|
|
|
|
// fix issue #17884
|
2017-07-03 09:15:53 +08:00
|
|
|
if (dynamic_cast<ActionInstant*>(_actions[1]))
|
|
|
|
return (_done && _actions[1]->isDone());
|
|
|
|
else
|
|
|
|
return _done;
|
2017-06-08 14:52:36 +08:00
|
|
|
}
|
|
|
|
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
if (_actions[0] && _actions[1])
|
|
|
|
{
|
|
|
|
return Sequence::create(_actions[0]->clone(), _actions[1]->clone(), nullptr);
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Sequence::Sequence()
|
2016-04-19 16:11:54 +08:00
|
|
|
: _split(0)
|
2016-04-08 13:40:36 +08:00
|
|
|
{
|
|
|
|
_actions[0] = nullptr;
|
|
|
|
_actions[1] = nullptr;
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
Sequence::~Sequence()
|
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
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
if (target == nullptr)
|
|
|
|
{
|
|
|
|
log("Sequence::startWithTarget error: target is nullptr!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_actions[0] == nullptr || _actions[1] == nullptr)
|
|
|
|
{
|
|
|
|
log("Sequence::startWithTarget error: _actions[0] or _actions[1] is nullptr!");
|
|
|
|
return;
|
|
|
|
}
|
2016-04-19 16:11:54 +08:00
|
|
|
if (_duration > FLT_EPSILON)
|
2017-01-17 09:48:30 +08:00
|
|
|
// fix #14936 - FLT_EPSILON (instant action) / very fast duration (0.001) leads to worng split, that leads to call instant action few times
|
|
|
|
_split = _actions[0]->getDuration() > FLT_EPSILON ? _actions[0]->getDuration() / _duration : 0;
|
2016-04-08 13:40:36 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
2013-06-15 14:03:30 +08:00
|
|
|
_last = -1;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2017-06-08 17:07:43 +08:00
|
|
|
void Sequence::stop()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// Issue #1305
|
2016-04-08 13:40:36 +08:00
|
|
|
if( _last != - 1 && _actions[_last])
|
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
|
|
|
|
2016-04-08 13:40:36 +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;
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if ( found==1 )
|
|
|
|
{
|
|
|
|
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);
|
2015-08-27 17:55:38 +08:00
|
|
|
if (!(sendUpdateEventToScript(1.0f, _actions[0])))
|
|
|
|
_actions[0]->update(1.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_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.
|
2015-08-27 17:55:38 +08:00
|
|
|
if (!(sendUpdateEventToScript(1.0f, _actions[0])))
|
|
|
|
_actions[0]->update(1.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_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.
|
2015-09-22 16:08:23 +08:00
|
|
|
// "step" should be overridden, and the "reverseMode" value propagated to inner Sequences.
|
2015-08-27 17:55:38 +08:00
|
|
|
if (!(sendUpdateEventToScript(0, _actions[1])))
|
|
|
|
_actions[1]->update(0);
|
2015-01-08 10:22:45 +08:00
|
|
|
_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
|
|
|
}
|
2015-08-27 17:55:38 +08:00
|
|
|
if (!(sendUpdateEventToScript(new_t, _actions[found])))
|
|
|
|
_actions[found]->update(new_t);
|
2013-06-15 14:03:30 +08:00
|
|
|
_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
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
if (_actions[0] && _actions[1])
|
|
|
|
return Sequence::createWithTwoActions(_actions[1]->reverse(), _actions[0]->reverse());
|
|
|
|
else
|
|
|
|
return nullptr;
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (repeat && repeat->initWithAction(action, times))
|
|
|
|
{
|
|
|
|
repeat->autorelease();
|
|
|
|
return repeat;
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete repeat;
|
|
|
|
return nullptr;
|
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
|
|
|
{
|
2018-01-19 13:40:41 +08:00
|
|
|
if (action && ActionInterval::initWithDuration(action->getDuration() * times))
|
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
|
2016-03-30 14:05:22 +08:00
|
|
|
// minggo: instant action doesn't execute action in Repeat::startWithTarget(), so comment it.
|
|
|
|
// if (_actionInstant)
|
|
|
|
// {
|
|
|
|
// _times -=1;
|
|
|
|
// }
|
2013-06-15 14:03:30 +08:00
|
|
|
_total = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-08 17:07:43 +08:00
|
|
|
Repeat* Repeat::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return Repeat::create(_innerAction->clone(), _times);
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2017-06-08 17:07:43 +08:00
|
|
|
Repeat::~Repeat()
|
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
|
|
|
}
|
|
|
|
|
2017-06-08 17:07:43 +08:00
|
|
|
void Repeat::stop()
|
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
|
|
|
{
|
2016-03-30 14:05:22 +08:00
|
|
|
while (dt >= _nextDt && _total < _times)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2015-08-27 17:55:38 +08:00
|
|
|
if (!(sendUpdateEventToScript(1.0f, _innerAction)))
|
|
|
|
_innerAction->update(1.0f);
|
2013-06-15 14:03:30 +08:00
|
|
|
_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
|
2016-07-12 03:13:56 +08:00
|
|
|
if (std::abs(dt - 1.0f) < FLT_EPSILON && _total < _times)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-03-30 14:05:22 +08:00
|
|
|
if (!(sendUpdateEventToScript(1.0f, _innerAction)))
|
|
|
|
_innerAction->update(1.0f);
|
|
|
|
|
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
|
|
|
{
|
2016-03-30 14:05:22 +08:00
|
|
|
// minggo: inner action update is invoked above, don't have to invoke it here
|
|
|
|
// if (!(sendUpdateEventToScript(1, _innerAction)))
|
|
|
|
// _innerAction->update(1);
|
2013-06-15 14:03:30 +08:00
|
|
|
_innerAction->stop();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// issue #390 prevent jerk, use right update
|
2015-08-27 17:55:38 +08:00
|
|
|
if (!(sendUpdateEventToScript(dt - (_nextDt - _innerAction->getDuration()/_duration), _innerAction)))
|
|
|
|
_innerAction->update(dt - (_nextDt - _innerAction->getDuration()/_duration));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-27 17:55:38 +08:00
|
|
|
if (!(sendUpdateEventToScript(fmodf(dt * _times,1.0f), _innerAction)))
|
|
|
|
_innerAction->update(fmodf(dt * _times,1.0f));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-08 17:07:43 +08:00
|
|
|
bool Repeat::isDone() 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
|
|
|
}
|
2016-04-08 13:40:36 +08:00
|
|
|
|
|
|
|
delete ret;
|
2013-12-18 17:47:20 +08:00
|
|
|
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
|
|
|
{
|
2015-07-14 15:28:36 +08:00
|
|
|
CCASSERT(action != nullptr, "action can't be nullptr!");
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action == nullptr)
|
|
|
|
{
|
|
|
|
log("RepeatForever::initWithAction error:action is nullptr!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
action->retain();
|
|
|
|
_innerAction = action;
|
2016-04-08 13:40:36 +08:00
|
|
|
|
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
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
// no copy constructor
|
|
|
|
return RepeatForever::create(_innerAction->clone());
|
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);
|
2017-05-23 08:46:44 +08:00
|
|
|
// only action interval should prevent jerk, issue #17808
|
|
|
|
if (_innerAction->isDone() && _innerAction->getDuration() > 0)
|
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);
|
2017-05-23 08:46:44 +08:00
|
|
|
// to prevent jerk. cocos2d-iphone 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
|
|
|
|
2015-05-09 00:19:13 +08:00
|
|
|
#if (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
|
|
|
{
|
2015-12-04 04:16:21 +08:00
|
|
|
Spawn* ret = new (std::nothrow) Spawn;
|
2016-04-08 13:40:36 +08:00
|
|
|
|
2015-12-04 04:16:21 +08:00
|
|
|
if (ret && ret->init(arrayOfActions))
|
2016-04-08 13:40:36 +08:00
|
|
|
{
|
2015-12-04 04:16:21 +08:00
|
|
|
ret->autorelease();
|
2016-04-08 13:40:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete ret;
|
|
|
|
return nullptr;
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (spawn && spawn->initWithTwoActions(action1, action2))
|
|
|
|
{
|
|
|
|
spawn->autorelease();
|
|
|
|
return spawn;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete spawn;
|
|
|
|
return nullptr;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2015-12-04 04:16:21 +08:00
|
|
|
bool Spawn::init(const Vector<FiniteTimeAction*>& arrayOfActions)
|
|
|
|
{
|
|
|
|
auto count = arrayOfActions.size();
|
2016-04-08 13:40:36 +08:00
|
|
|
|
2015-12-04 04:16:21 +08:00
|
|
|
if (count == 0)
|
2016-04-08 13:40:36 +08:00
|
|
|
return false;
|
|
|
|
|
2015-12-04 04:16:21 +08:00
|
|
|
if (count == 1)
|
|
|
|
return initWithTwoActions(arrayOfActions.at(0), ExtraAction::create());
|
2016-04-08 13:40:36 +08:00
|
|
|
|
2015-12-04 04:16:21 +08:00
|
|
|
// else count > 1
|
|
|
|
auto prev = arrayOfActions.at(0);
|
|
|
|
for (int i = 1; i < count-1; ++i)
|
|
|
|
{
|
|
|
|
prev = createWithTwoActions(prev, arrayOfActions.at(i));
|
|
|
|
}
|
2016-04-08 13:40:36 +08:00
|
|
|
|
2015-12-04 04:16:21 +08:00
|
|
|
return initWithTwoActions(prev, arrayOfActions.at(count-1));
|
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool Spawn::initWithTwoActions(FiniteTimeAction *action1, FiniteTimeAction *action2)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2015-07-14 15:28:36 +08:00
|
|
|
CCASSERT(action1 != nullptr, "action1 can't be nullptr!");
|
|
|
|
CCASSERT(action2 != nullptr, "action2 can't be nullptr!");
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action1 == nullptr || action2 == nullptr)
|
|
|
|
{
|
|
|
|
log("Spawn::initWithTwoActions error: action is nullptr!");
|
|
|
|
return false;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2017-06-08 17:07:43 +08:00
|
|
|
Spawn* Spawn::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
// no copy constructor
|
|
|
|
if (_one && _two)
|
|
|
|
return Spawn::createWithTwoActions(_one->clone(), _two->clone());
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-06-14 08:25:14 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
Spawn::Spawn()
|
|
|
|
: _one(nullptr)
|
|
|
|
, _two(nullptr)
|
|
|
|
{
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2017-06-08 17:07:43 +08:00
|
|
|
Spawn::~Spawn()
|
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
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
if (target == nullptr)
|
|
|
|
{
|
|
|
|
log("Spawn::startWithTarget error: target is nullptr!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_one == nullptr || _two == nullptr)
|
|
|
|
{
|
|
|
|
log("Spawn::startWithTarget error: _one or _two is nullptr!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-06-08 17:07:43 +08:00
|
|
|
void Spawn::stop()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
if (_one)
|
|
|
|
_one->stop();
|
|
|
|
|
|
|
|
if (_two)
|
|
|
|
_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
|
|
|
{
|
2015-08-27 17:55:38 +08:00
|
|
|
if (!(sendUpdateEventToScript(time, _one)))
|
|
|
|
_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
|
|
|
{
|
2015-08-27 17:55:38 +08:00
|
|
|
if (!(sendUpdateEventToScript(time, _two)))
|
|
|
|
_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
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
if (_one && _two)
|
|
|
|
return Spawn::createWithTwoActions(_one->reverse(), _two->reverse());
|
|
|
|
|
|
|
|
return nullptr;
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (rotateTo && rotateTo->initWithDuration(duration, dstAngle, dstAngle))
|
|
|
|
{
|
|
|
|
rotateTo->autorelease();
|
|
|
|
return rotateTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete rotateTo;
|
|
|
|
return nullptr;
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (rotateTo && rotateTo->initWithDuration(duration, dstAngleX, dstAngleY))
|
|
|
|
{
|
|
|
|
rotateTo->autorelease();
|
|
|
|
return rotateTo;
|
|
|
|
}
|
2014-07-31 03:01:18 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete rotateTo;
|
|
|
|
return nullptr;
|
2014-07-31 03:01:18 +08:00
|
|
|
}
|
|
|
|
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if(rotateTo && rotateTo->initWithDuration(duration, dstAngle3D))
|
|
|
|
{
|
|
|
|
rotateTo->autorelease();
|
|
|
|
return rotateTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete rotateTo;
|
|
|
|
return nullptr;
|
2014-07-31 03:01:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-08 17:07:43 +08:00
|
|
|
RotateTo* RotateTo::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) 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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (rotateBy && rotateBy->initWithDuration(duration, deltaAngle))
|
|
|
|
{
|
|
|
|
rotateBy->autorelease();
|
|
|
|
return rotateBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete rotateBy;
|
|
|
|
return nullptr;
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (rotateBy && rotateBy->initWithDuration(duration, deltaAngleX, deltaAngleY))
|
|
|
|
{
|
|
|
|
rotateBy->autorelease();
|
|
|
|
return rotateBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete rotateBy;
|
|
|
|
return nullptr;
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
|
|
|
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if(rotateBy && rotateBy->initWithDuration(duration, deltaAngle3D))
|
|
|
|
{
|
|
|
|
rotateBy->autorelease();
|
|
|
|
return rotateBy;
|
|
|
|
}
|
2014-02-23 11:16:42 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete rotateBy;
|
|
|
|
return nullptr;
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (ret && ret->initWithDuration(duration, deltaPosition))
|
2014-12-22 14:34:35 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2014-12-22 14:34:35 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete ret;
|
|
|
|
return nullptr;
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return MoveBy::create(_duration, _positionDelta);
|
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();
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (ret && ret->initWithDuration(duration, position))
|
2014-12-22 14:34:35 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2014-12-22 14:34:35 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete ret;
|
|
|
|
return nullptr;
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return MoveTo::create(_duration, _endPosition);
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (skewTo && skewTo->initWithDuration(t, sx, sy))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
skewTo->autorelease();
|
|
|
|
return skewTo;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete skewTo;
|
|
|
|
return nullptr;
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return SkewTo::create(_duration, _endSkewX, _endSkewY);
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (skewBy && skewBy->initWithDuration(t, sx, sy))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
skewBy->autorelease();
|
|
|
|
return skewBy;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete skewBy;
|
|
|
|
return nullptr;
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return SkewBy::create(_duration, _skewX, _skewY);
|
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
|
|
|
}
|
|
|
|
|
2016-08-16 16:55:31 +08:00
|
|
|
ResizeTo* ResizeTo::create(float duration, const cocos2d::Size& final_size)
|
|
|
|
{
|
|
|
|
ResizeTo *ret = new (std::nothrow) ResizeTo();
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (ret->initWithDuration(duration, final_size))
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete ret;
|
|
|
|
ret = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-06-08 17:07:43 +08:00
|
|
|
ResizeTo* ResizeTo::clone() const
|
2016-08-16 16:55:31 +08:00
|
|
|
{
|
|
|
|
// no copy constructor
|
|
|
|
ResizeTo* a = new (std::nothrow) ResizeTo();
|
|
|
|
a->initWithDuration(_duration, _finalSize);
|
|
|
|
a->autorelease();
|
|
|
|
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResizeTo::startWithTarget(cocos2d::Node* target)
|
|
|
|
{
|
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_initialSize = target->getContentSize();
|
|
|
|
_sizeDelta = _finalSize - _initialSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResizeTo::update(float time)
|
|
|
|
{
|
|
|
|
if (_target)
|
|
|
|
{
|
|
|
|
auto new_size = _initialSize + (_sizeDelta * time);
|
|
|
|
_target->setContentSize(new_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ResizeTo::initWithDuration(float duration, const cocos2d::Size& final_size)
|
|
|
|
{
|
|
|
|
if (cocos2d::ActionInterval::initWithDuration(duration))
|
|
|
|
{
|
|
|
|
_finalSize = final_size;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ResizeBy
|
|
|
|
//
|
|
|
|
|
|
|
|
ResizeBy* ResizeBy::create(float duration, const cocos2d::Size& deltaSize)
|
|
|
|
{
|
|
|
|
ResizeBy *ret = new (std::nothrow) ResizeBy();
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (ret->initWithDuration(duration, deltaSize))
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete ret;
|
|
|
|
ret = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResizeBy* ResizeBy::clone() const
|
|
|
|
{
|
|
|
|
// no copy constructor
|
|
|
|
auto a = new (std::nothrow) ResizeBy();
|
|
|
|
a->initWithDuration(_duration, _sizeDelta);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResizeBy::startWithTarget(Node *target)
|
|
|
|
{
|
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_previousSize = _startSize = target->getContentSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
ResizeBy* ResizeBy::reverse() const
|
|
|
|
{
|
|
|
|
cocos2d::Size newSize(-_sizeDelta.width, -_sizeDelta.height);
|
|
|
|
return ResizeBy::create(_duration, newSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResizeBy::update(float t)
|
|
|
|
{
|
|
|
|
if (_target)
|
|
|
|
{
|
|
|
|
_target->setContentSize(_startSize + (_sizeDelta * t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ResizeBy::initWithDuration(float duration, const cocos2d::Size& deltaSize)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if (ActionInterval::initWithDuration(duration))
|
|
|
|
{
|
|
|
|
_sizeDelta = deltaSize;
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (jumpBy && jumpBy->initWithDuration(duration, position, height, jumps))
|
|
|
|
{
|
|
|
|
jumpBy->autorelease();
|
|
|
|
return jumpBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete jumpBy;
|
|
|
|
return nullptr;
|
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");
|
2016-04-08 13:40:36 +08:00
|
|
|
if (jumps < 0)
|
|
|
|
{
|
|
|
|
log("JumpBy::initWithDuration error: Number of jumps must be >= 0");
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-20 13:01:27 +08:00
|
|
|
|
|
|
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return JumpBy::create(_duration, _delta, _height, _jumps);
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (jumpTo && jumpTo->initWithDuration(duration, position, height, jumps))
|
|
|
|
{
|
|
|
|
jumpTo->autorelease();
|
|
|
|
return jumpTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete jumpTo;
|
|
|
|
return nullptr;
|
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");
|
2016-04-08 13:40:36 +08:00
|
|
|
if (jumps < 0)
|
|
|
|
{
|
|
|
|
log("JumpTo::initWithDuration error:Number of jumps must be >= 0");
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-03 00:13:57 +08:00
|
|
|
|
|
|
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return JumpTo::create(_duration, _endPosition, _height, _jumps);
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (bezierBy && bezierBy->initWithDuration(t, c))
|
|
|
|
{
|
|
|
|
bezierBy->autorelease();
|
|
|
|
return bezierBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete bezierBy;
|
|
|
|
return nullptr;
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return BezierBy::create(_duration, _config);
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (bezierTo && bezierTo->initWithDuration(t, c))
|
|
|
|
{
|
|
|
|
bezierTo->autorelease();
|
|
|
|
return bezierTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete bezierTo;
|
|
|
|
return nullptr;
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return BezierTo::create(_duration, _toConfig);
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (scaleTo && scaleTo->initWithDuration(duration, s))
|
|
|
|
{
|
|
|
|
scaleTo->autorelease();
|
|
|
|
return scaleTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete scaleTo;
|
|
|
|
return nullptr;
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (scaleTo && scaleTo->initWithDuration(duration, sx, sy))
|
|
|
|
{
|
|
|
|
scaleTo->autorelease();
|
|
|
|
return scaleTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete scaleTo;
|
|
|
|
return nullptr;
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (scaleTo && scaleTo->initWithDuration(duration, sx, sy, sz))
|
|
|
|
{
|
|
|
|
scaleTo->autorelease();
|
|
|
|
return scaleTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete scaleTo;
|
|
|
|
return nullptr;
|
2014-03-19 16:23:14 +08:00
|
|
|
}
|
|
|
|
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return ScaleTo::create(_duration, _endScaleX, _endScaleY, _endScaleZ);
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (scaleBy && scaleBy->initWithDuration(duration, s))
|
|
|
|
{
|
|
|
|
scaleBy->autorelease();
|
|
|
|
return scaleBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete scaleBy;
|
|
|
|
return nullptr;
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (scaleBy && scaleBy->initWithDuration(duration, sx, sy, 1.f))
|
|
|
|
{
|
|
|
|
scaleBy->autorelease();
|
|
|
|
return scaleBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete scaleBy;
|
|
|
|
return nullptr;
|
2014-03-19 16:23:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (scaleBy && scaleBy->initWithDuration(duration, sx, sy, sz))
|
|
|
|
{
|
|
|
|
scaleBy->autorelease();
|
|
|
|
return scaleBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete scaleBy;
|
|
|
|
return nullptr;
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return ScaleBy::create(_duration, _endScaleX, _endScaleY, _endScaleZ);
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (blink && blink->initWithDuration(duration, blinks))
|
|
|
|
{
|
|
|
|
blink->autorelease();
|
|
|
|
return blink;
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete blink;
|
|
|
|
return nullptr;
|
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");
|
2016-04-08 13:40:36 +08:00
|
|
|
if (blinks < 0)
|
|
|
|
{
|
|
|
|
log("Blink::initWithDuration error:blinks should be >= 0");
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-20 13:01:27 +08:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2016-05-25 02:09:11 +08:00
|
|
|
if (nullptr != _target)
|
2015-06-03 18:39:16 +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
|
|
|
}
|
|
|
|
|
2017-06-08 17:07:43 +08:00
|
|
|
Blink* Blink::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return Blink::create(_duration, _times);
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action && action->initWithDuration(d,255.0f))
|
|
|
|
{
|
|
|
|
action->autorelease();
|
|
|
|
return action;
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete action;
|
|
|
|
return nullptr;
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return FadeIn::create(_duration);
|
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);
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (nullptr != _reverseAction)
|
2014-02-25 15:30:54 +08:00
|
|
|
this->_toOpacity = this->_reverseAction->_fromOpacity;
|
2016-04-08 13:40:36 +08:00
|
|
|
else
|
2014-02-25 15:30:54 +08:00
|
|
|
_toOpacity = 255.0f;
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (target)
|
2014-02-25 15:30:54 +08:00
|
|
|
_fromOpacity = target->getOpacity();
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action && action->initWithDuration(d,0.0f))
|
|
|
|
{
|
|
|
|
action->autorelease();
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete action;
|
|
|
|
return nullptr;
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return FadeOut::create(_duration);
|
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);
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (nullptr != _reverseAction)
|
2014-02-25 15:30:54 +08:00
|
|
|
_toOpacity = _reverseAction->_fromOpacity;
|
2016-04-08 13:40:36 +08:00
|
|
|
else
|
2014-02-25 15:30:54 +08:00
|
|
|
_toOpacity = 0.0f;
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (target)
|
2014-02-25 15:30:54 +08:00
|
|
|
_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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (fadeTo && fadeTo->initWithDuration(duration, opacity))
|
|
|
|
{
|
|
|
|
fadeTo->autorelease();
|
|
|
|
return fadeTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete fadeTo;
|
|
|
|
return nullptr;
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return FadeTo::create(_duration, _toOpacity);
|
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-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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (tintTo && tintTo->initWithDuration(duration, red, green, blue))
|
|
|
|
{
|
|
|
|
tintTo->autorelease();
|
|
|
|
return tintTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete tintTo;
|
|
|
|
return nullptr;
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return TintTo::create(_duration, _to.r, _to.g, _to.b);
|
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-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)));
|
2016-04-08 13:40:36 +08:00
|
|
|
}
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (tintBy && tintBy->initWithDuration(duration, deltaRed, deltaGreen, deltaBlue))
|
|
|
|
{
|
|
|
|
tintBy->autorelease();
|
|
|
|
return tintBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete tintBy;
|
|
|
|
return nullptr;
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return TintBy::create(_duration, _deltaR, _deltaG, _deltaB);
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action && action->initWithDuration(d))
|
|
|
|
{
|
|
|
|
action->autorelease();
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete action;
|
|
|
|
return nullptr;
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return DelayTime::create(_duration);
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void DelayTime::update(float /*time*/)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (reverseTime && reverseTime->initWithAction( action->clone() ))
|
|
|
|
{
|
|
|
|
reverseTime->autorelease();
|
|
|
|
return reverseTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete reverseTime;
|
|
|
|
return nullptr;
|
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
|
|
|
{
|
2015-07-14 15:28:36 +08:00
|
|
|
CCASSERT(action != nullptr, "action can't be nullptr!");
|
|
|
|
CCASSERT(action != _other, "action doesn't equal to _other!");
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action == nullptr || action == _other)
|
|
|
|
{
|
|
|
|
log("ReverseTime::initWithAction error: action is null or action equal to _other");
|
|
|
|
return false;
|
|
|
|
}
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return ReverseTime::create(_other->clone());
|
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
|
|
|
}
|
|
|
|
|
2017-06-08 17:07:43 +08:00
|
|
|
void ReverseTime::stop()
|
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
|
|
|
{
|
2015-08-27 17:55:38 +08:00
|
|
|
if (!(sendUpdateEventToScript(1 - time, _other)))
|
|
|
|
_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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (animate && animate->initWithAnimation(animation))
|
|
|
|
{
|
|
|
|
animate->autorelease();
|
|
|
|
return animate;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete animate;
|
|
|
|
return nullptr;
|
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)
|
2015-07-13 10:40:43 +08:00
|
|
|
, _currFrameIndex(0)
|
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");
|
2016-04-08 13:40:36 +08:00
|
|
|
if (animation == nullptr)
|
|
|
|
{
|
|
|
|
log("Animate::initWithAnimation: argument Animation must be non-nullptr");
|
|
|
|
return false;
|
|
|
|
}
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
return Animate::create(_animation->clone());
|
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
|
|
|
{
|
2016-05-26 08:34:18 +08:00
|
|
|
auto blend = static_cast<Sprite*>(_target)->getBlendFunc();
|
2013-12-25 16:06:39 +08:00
|
|
|
static_cast<Sprite*>(_target)->setSpriteFrame(_origFrame);
|
2016-05-26 08:34:18 +08:00
|
|
|
static_cast<Sprite*>(_target)->setBlendFunc(blend);
|
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
|
2016-04-08 13:40:36 +08:00
|
|
|
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;
|
2016-04-08 13:40:36 +08:00
|
|
|
if( loopNumber > _executedLoops )
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_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
|
|
|
|
2016-04-08 13:40:36 +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
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if( splitTime <= t )
|
|
|
|
{
|
2016-05-26 08:34:18 +08:00
|
|
|
auto blend = static_cast<Sprite*>(_target)->getBlendFunc();
|
2015-07-13 10:40:43 +08:00
|
|
|
_currFrameIndex = i;
|
|
|
|
AnimationFrame* frame = frames.at(_currFrameIndex);
|
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);
|
2016-05-26 08:34:18 +08:00
|
|
|
static_cast<Sprite*>(_target)->setBlendFunc(blend);
|
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
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (!oldArray.empty())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-10-27 15:10:24 +08:00
|
|
|
for (auto iter = oldArray.crbegin(), iterCrend = oldArray.crend(); iter != iterCrend; ++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();
|
2016-04-08 13:40:36 +08:00
|
|
|
if (p && p->initWithTarget(target, action))
|
|
|
|
{
|
|
|
|
p->autorelease();
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete p;
|
|
|
|
return nullptr;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
// no copy constructor
|
2013-06-15 14:03:30 +08:00
|
|
|
// win32 : use the _other's copy object.
|
2016-04-08 13:40:36 +08:00
|
|
|
return TargetedAction::create(_forcedTarget, _action->clone());
|
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
|
|
|
{
|
2015-08-27 17:55:38 +08:00
|
|
|
if (!(sendUpdateEventToScript(time, _action)))
|
|
|
|
_action->update(time);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-20 04:16:38 +08:00
|
|
|
void TargetedAction::setForcedTarget(Node* forcedTarget)
|
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
if( _forcedTarget != forcedTarget )
|
|
|
|
{
|
2013-07-20 04:16:38 +08:00
|
|
|
CC_SAFE_RETAIN(forcedTarget);
|
|
|
|
CC_SAFE_RELEASE(_forcedTarget);
|
|
|
|
_forcedTarget = forcedTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 17:48:19 +08:00
|
|
|
// ActionFloat
|
2015-04-18 20:35:14 +08:00
|
|
|
|
2015-04-28 17:48:19 +08:00
|
|
|
ActionFloat* ActionFloat::create(float duration, float from, float to, ActionFloatCallback callback)
|
2015-04-18 20:35:14 +08:00
|
|
|
{
|
2015-04-28 17:48:19 +08:00
|
|
|
auto ref = new (std::nothrow) ActionFloat();
|
2015-04-18 20:35:14 +08:00
|
|
|
if (ref && ref->initWithDuration(duration, from, to, callback))
|
|
|
|
{
|
|
|
|
ref->autorelease();
|
|
|
|
return ref;
|
|
|
|
}
|
2016-04-08 13:40:36 +08:00
|
|
|
|
|
|
|
delete ref;
|
|
|
|
return nullptr;
|
2015-04-18 20:35:14 +08:00
|
|
|
}
|
|
|
|
|
2015-04-28 17:48:19 +08:00
|
|
|
bool ActionFloat::initWithDuration(float duration, float from, float to, ActionFloatCallback callback)
|
2015-04-18 20:35:14 +08:00
|
|
|
{
|
|
|
|
if (ActionInterval::initWithDuration(duration))
|
|
|
|
{
|
|
|
|
_from = from;
|
|
|
|
_to = to;
|
|
|
|
_callback = callback;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-28 17:48:19 +08:00
|
|
|
ActionFloat* ActionFloat::clone() const
|
2015-04-18 20:35:14 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
return ActionFloat::create(_duration, _from, _to, _callback);
|
2015-04-18 20:35:14 +08:00
|
|
|
}
|
|
|
|
|
2015-04-28 17:48:19 +08:00
|
|
|
void ActionFloat::startWithTarget(Node *target)
|
2015-04-18 20:35:14 +08:00
|
|
|
{
|
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_delta = _to - _from;
|
|
|
|
}
|
|
|
|
|
2015-04-28 17:48:19 +08:00
|
|
|
void ActionFloat::update(float delta)
|
2015-04-18 20:35:14 +08:00
|
|
|
{
|
|
|
|
float value = _to - _delta * (1 - delta);
|
|
|
|
|
|
|
|
if (_callback)
|
|
|
|
{
|
2015-04-28 17:48:19 +08:00
|
|
|
// report back value to caller
|
2015-04-18 20:35:14 +08:00
|
|
|
_callback(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 17:48:19 +08:00
|
|
|
ActionFloat* ActionFloat::reverse() const
|
2015-04-18 20:35:14 +08:00
|
|
|
{
|
2015-04-28 17:48:19 +08:00
|
|
|
return ActionFloat::create(_duration, _to, _from, _callback);
|
2015-04-18 20:35:14 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|