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-07-09 01:23:11 +08:00
|
|
|
https://axis-project.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
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __CCACTIONTWEEN_H__
|
|
|
|
#define __CCACTIONTWEEN_H__
|
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCActionInterval.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
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup actions
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2015-03-18 18:15:34 +08:00
|
|
|
/**
|
|
|
|
@brief The delegate class for ActionTween.
|
2015-03-19 15:59:58 +08:00
|
|
|
@details If you want to use ActionTween on a node.
|
2015-03-18 18:15:34 +08:00
|
|
|
You should implement the node follow these steps:
|
|
|
|
1. The node should be inherit from ActionTweenDelegate.
|
|
|
|
2. Override the virtual method updateTweenAction in the node.
|
|
|
|
|
2015-09-22 16:08:23 +08:00
|
|
|
Then once you running ActionTween on the node, the method updateTweenAction will be invoked.
|
2015-03-18 18:15:34 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL ActionTweenDelegate
|
2012-04-17 16:00:18 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual ~ActionTweenDelegate() {}
|
2015-03-18 18:15:34 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief The callback function when ActionTween is running.
|
|
|
|
@param value The new value of the specified key.
|
|
|
|
@param key The key of property which should be updated.
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
virtual void updateTweenAction(float value, std::string_view key) = 0;
|
2012-04-17 16:00:18 +08:00
|
|
|
};
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** ActionTween
|
2012-04-17 16:00:18 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionTween is an action that lets you update any property of an object.
|
2012-04-17 16:00:18 +08:00
|
|
|
For example, if you want to modify the "width" property of a target from 200 to 300 in 2 seconds, then:
|
|
|
|
|
2013-08-01 16:57:42 +08:00
|
|
|
@code
|
|
|
|
auto modifyWidth = ActionTween::create(2, "width", 200, 300);
|
|
|
|
target->runAction(modifyWidth);
|
|
|
|
@endcode
|
2012-04-17 16:00:18 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Another example: ScaleTo action could be rewritten using PropertyAction:
|
2012-04-17 16:00:18 +08:00
|
|
|
|
2013-08-01 16:57:42 +08:00
|
|
|
@code
|
|
|
|
// scaleA and scaleB are equivalents
|
|
|
|
auto scaleA = ScaleTo::create(2, 3); // (duration, to)
|
|
|
|
auto scaleB = ActionTween::create(2, "scale", 1, 3); // (duration, key, from, to)
|
|
|
|
@endcode
|
2012-04-17 16:00:18 +08:00
|
|
|
|
|
|
|
@since v0.99.2
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL ActionTween : public ActionInterval
|
2012-04-17 16:00:18 +08:00
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-18 18:15:34 +08:00
|
|
|
* @brief Create and initializes the action with the property name (key), and the from and to parameters.
|
|
|
|
* @param duration The duration of the ActionTween. It's a value in seconds.
|
|
|
|
* @param key The key of property which should be updated.
|
|
|
|
* @param from The value of the specified property when the action begin.
|
|
|
|
* @param to The value of the specified property when the action end.
|
|
|
|
* @return If the creation success, return a pointer of ActionTween; otherwise, return nil.
|
2015-01-20 15:41:59 +08:00
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static ActionTween* create(float duration, std::string_view key, float from, float to);
|
2012-04-17 16:00:18 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
// Overrides
|
2021-12-25 10:04:45 +08:00
|
|
|
void startWithTarget(Node* target) override;
|
2013-07-18 07:56:19 +08:00
|
|
|
void update(float dt) override;
|
|
|
|
ActionTween* reverse() const override;
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionTween* clone() const override;
|
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
/**
|
|
|
|
* @brief Initializes the action with the property name (key), and the from and to parameters.
|
|
|
|
* @param duration The duration of the ActionTween. It's a value in seconds.
|
|
|
|
* @param key The key of property which should be updated.
|
|
|
|
* @param from The value of the specified property when the action begin.
|
|
|
|
* @param to The value of the specified property when the action end.
|
|
|
|
* @return If the initialization success, return true; otherwise, return false.
|
|
|
|
*/
|
|
|
|
bool initWithDuration(float duration, std::string_view key, float from, float to);
|
2013-06-14 08:25:14 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string _key;
|
|
|
|
float _from, _to;
|
|
|
|
float _delta;
|
2012-04-17 16:00:18 +08:00
|
|
|
};
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of actions group
|
|
|
|
/// @}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2012-04-17 16:00:18 +08:00
|
|
|
|
|
|
|
#endif /* __CCACTIONTWEEN_H__ */
|