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
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2012-04-17 16:00:18 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
ActionTween* ActionTween::create(float duration, std::string_view key, float from, float to)
|
2012-04-17 16:00:18 +08:00
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
ActionTween* ret = new ActionTween();
|
|
|
|
if (ret->initWithDuration(duration, key, from, to))
|
2012-04-17 16:00:18 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
ret->autorelease();
|
2016-04-08 13:40:36 +08:00
|
|
|
return ret;
|
2012-04-17 16:00:18 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete ret;
|
|
|
|
return nullptr;
|
2012-04-17 16:00:18 +08:00
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
bool ActionTween::initWithDuration(float duration, std::string_view 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
|
|
|
{
|
2021-12-25 10:04:45 +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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionTween* ActionTween::clone() const
|
2013-06-14 08:25:14 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
return ActionTween::create(_duration, _key, _from, _to);
|
2013-06-14 08:25:14 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ActionTween::startWithTarget(Node* target)
|
2012-04-17 16:00:18 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
dynamic_cast<ActionTweenDelegate*>(_target)->updateTweenAction(_to - _delta * (1 - dt), _key);
|
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
|
|
|
{
|
2016-02-03 23:12:37 +08:00
|
|
|
return ActionTween::create(_duration, _key, _to, _from);
|
2012-04-17 16:00:18 +08:00
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|