2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2009 lhunath (Maarten Billemont)
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2014-01-07 11:25:07 +08:00
|
|
|
CopyRight (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
2012-04-17 16:00:18 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCActionTween.h"
|
2012-04-17 16:00:18 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-11-16 04:04:47 +08:00
|
|
|
ActionTween* ActionTween::create(float aDuration, const std::string& key, float from, float to)
|
2012-04-17 16:00:18 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
ActionTween* ret = new ActionTween();
|
|
|
|
if (ret && ret->initWithDuration(aDuration, key, from, to))
|
2012-04-17 16:00:18 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
ret->autorelease();
|
2012-04-17 16:00:18 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-04-17 16:00:18 +08:00
|
|
|
}
|
2013-12-18 17:47:20 +08:00
|
|
|
return ret;
|
2012-04-17 16:00:18 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool ActionTween::initWithDuration(float duration, const std::string& key, float from, float to)
|
2012-04-17 16:00:18 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-17 16:00:18 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_key = key;
|
|
|
|
_to = to;
|
|
|
|
_from = from;
|
2012-04-17 16:00:18 +08:00
|
|
|
return true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-17 16:00:18 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return false;
|
2012-04-17 16:00:18 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionTween *ActionTween::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new ActionTween();
|
2013-06-15 14:03:30 +08:00
|
|
|
a->initWithDuration(_duration, _key.c_str(), _from, _to);
|
2013-06-14 08:25:14 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void ActionTween::startWithTarget(Node *target)
|
2012-04-17 16:00:18 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(dynamic_cast<ActionTweenDelegate*>(target), "target must implement ActionTweenDelegate");
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
2013-06-15 14:03:30 +08:00
|
|
|
_delta = _to - _from;
|
2012-04-17 16:00:18 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ActionTween::update(float dt)
|
2012-04-17 16:00:18 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
dynamic_cast<ActionTweenDelegate*>(_target)->updateTweenAction(_to - _delta * (1 - dt), _key.c_str());
|
2012-04-17 16:00:18 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionTween* ActionTween::reverse() const
|
2012-04-17 16:00:18 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return ActionTween::create(_duration, _key.c_str(), _to, _from);
|
2012-04-17 16:00:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_CC_END
|