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
|
2012-04-19 14:35:52 +08:00
|
|
|
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.
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __ACTIONS_CCACTION_H__
|
|
|
|
#define __ACTIONS_CCACTION_H__
|
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "base/CCRef.h"
|
2021-10-23 23:27:14 +08:00
|
|
|
#include "math/CCMath.h"
|
2015-08-27 17:55:38 +08:00
|
|
|
#include "base/CCScriptSupport.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
class Node;
|
2015-08-27 17:55:38 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
enum
|
|
|
|
{
|
2015-08-27 17:55:38 +08:00
|
|
|
kActionUpdate
|
|
|
|
};
|
|
|
|
|
2012-06-20 18:07:27 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup actions
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-18 20:05:59 +08:00
|
|
|
* @brief Base class for Action objects.
|
2010-07-20 14:42:56 +08:00
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL Action : public Ref, public Clonable
|
2010-07-20 14:42:56 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-18 20:05:59 +08:00
|
|
|
/** Default tag used for all the actions. */
|
2013-08-29 03:42:25 +08:00
|
|
|
static const int INVALID_TAG = -1;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-12-13 06:38:12 +08:00
|
|
|
virtual std::string description() const;
|
2010-07-20 14:42:56 +08:00
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/** Returns a clone of action.
|
|
|
|
*
|
|
|
|
* @return A clone action.
|
|
|
|
*/
|
2014-07-18 14:53:00 +08:00
|
|
|
virtual Action* clone() const
|
2014-07-11 10:19:49 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(0);
|
2014-07-11 10:19:49 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
2010-07-20 14:42:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Returns a new action that performs the exact reverse of the action.
|
2015-03-18 20:05:59 +08:00
|
|
|
*
|
2016-01-27 09:42:25 +08:00
|
|
|
* @return A new action that performs the exact reverse of the action.
|
2015-03-19 18:41:11 +08:00
|
|
|
* @js NA
|
2015-03-18 20:05:59 +08:00
|
|
|
*/
|
2014-07-18 14:53:00 +08:00
|
|
|
virtual Action* reverse() const
|
2014-07-11 10:19:49 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(0);
|
2014-07-11 10:19:49 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
2013-07-16 03:43:22 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Return true if the action has finished.
|
|
|
|
*
|
2015-03-18 20:05:59 +08:00
|
|
|
* @return Is true if the action has finished.
|
|
|
|
*/
|
2013-11-16 21:08:00 +08:00
|
|
|
virtual bool isDone() const;
|
2010-07-20 14:42:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Called before the action start. It will also set the target.
|
2015-03-18 20:05:59 +08:00
|
|
|
*
|
|
|
|
* @param target A certain target.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void startWithTarget(Node* target);
|
2010-07-20 14:42:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-18 20:05:59 +08:00
|
|
|
* Called after the action has finished. It will set the 'target' to nil.
|
|
|
|
* IMPORTANT: You should never call "Action::stop()" manually. Instead, use: "target->stopAction(action);".
|
|
|
|
*/
|
2013-11-16 21:08:00 +08:00
|
|
|
virtual void stop();
|
2010-07-20 14:42:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Called every frame with it's delta time, dt in seconds. DON'T override unless you know what you are doing.
|
2015-03-18 20:05:59 +08:00
|
|
|
*
|
|
|
|
* @param dt In seconds.
|
|
|
|
*/
|
2012-06-08 13:55:28 +08:00
|
|
|
virtual void step(float dt);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-18 20:05:59 +08:00
|
|
|
* Called once per frame. time a value between 0 and 1.
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
* For example:
|
|
|
|
* - 0 Means that the action just started.
|
|
|
|
* - 0.5 Means that the action is in the middle.
|
|
|
|
* - 1 Means that the action is over.
|
|
|
|
*
|
|
|
|
* @param time A value between 0 and 1.
|
|
|
|
*/
|
2012-06-08 13:55:28 +08:00
|
|
|
virtual void update(float time);
|
2015-03-27 11:39:31 +08:00
|
|
|
/** Return certain target.
|
2015-03-18 20:05:59 +08:00
|
|
|
*
|
|
|
|
* @return A certain target.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
Node* getTarget() const { return _target; }
|
2021-12-25 10:04:45 +08:00
|
|
|
/** The action will modify the target properties.
|
2015-03-18 20:05:59 +08:00
|
|
|
*
|
|
|
|
* @param target A certain target.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void setTarget(Node* target) { _target = target; }
|
|
|
|
/** Return a original Target.
|
2015-03-18 20:05:59 +08:00
|
|
|
*
|
|
|
|
* @return A original Target.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
Node* getOriginalTarget() const { return _originalTarget; }
|
2021-12-25 10:04:45 +08:00
|
|
|
/**
|
2015-03-18 20:05:59 +08:00
|
|
|
* Set the original target, since target can be nil.
|
2021-12-25 10:04:45 +08:00
|
|
|
* Is the target that were used to run the action. Unless you are doing something complex, like ActionManager, you
|
|
|
|
* should NOT call this method. The target is 'assigned', it is not 'retained'.
|
2015-03-18 20:05:59 +08:00
|
|
|
* @since v0.8.2
|
|
|
|
*
|
|
|
|
* @param originalTarget Is 'assigned', it is not 'retained'.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void setOriginalTarget(Node* originalTarget) { _originalTarget = originalTarget; }
|
|
|
|
/** Returns a tag that is used to identify the action easily.
|
2015-03-18 20:05:59 +08:00
|
|
|
*
|
|
|
|
* @return A tag.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
int getTag() const { return _tag; }
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Changes the tag that is used to identify the action easily.
|
2015-03-18 20:05:59 +08:00
|
|
|
*
|
|
|
|
* @param tag Used to identify the action easily.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setTag(int tag) { _tag = tag; }
|
2015-05-28 15:52:49 +08:00
|
|
|
/** Returns a flag field that is used to group the actions easily.
|
|
|
|
*
|
|
|
|
* @return A tag.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
unsigned int getFlags() const { return _flags; }
|
2015-05-28 15:52:49 +08:00
|
|
|
/** Changes the flag field that is used to group the actions easily.
|
|
|
|
*
|
2016-07-03 23:42:10 +08:00
|
|
|
* @param flags Used to group the actions easily.
|
2015-05-28 15:52:49 +08:00
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setFlags(unsigned int flags) { _flags = flags; }
|
2010-07-20 14:42:56 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
Action();
|
2013-11-22 09:06:06 +08:00
|
|
|
virtual ~Action();
|
|
|
|
|
2014-08-21 15:11:33 +08:00
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
Node* _originalTarget;
|
|
|
|
/**
|
2015-03-18 20:05:59 +08:00
|
|
|
* The "target".
|
|
|
|
* The target will be set with the 'startWithTarget' method.
|
|
|
|
* When the 'stop' method is called, target will be set to nil.
|
|
|
|
* The target is 'assigned', it is not 'retained'.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
Node* _target;
|
2015-03-18 20:05:59 +08:00
|
|
|
/** The action tag. An identifier of the action. */
|
2021-12-25 10:04:45 +08:00
|
|
|
int _tag;
|
2015-05-28 15:52:49 +08:00
|
|
|
/** The action flag field. To categorize action into certain groups.*/
|
|
|
|
unsigned int _flags;
|
2013-11-22 09:06:06 +08:00
|
|
|
|
|
|
|
private:
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_DISALLOW_COPY_AND_ASSIGN(Action);
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/** @class FiniteTimeAction
|
|
|
|
* @brief
|
|
|
|
* Base class actions that do have a finite time duration.
|
|
|
|
* Possible actions:
|
|
|
|
* - An action with a duration of 0 seconds.
|
|
|
|
* - An action with a duration of 35.5 seconds.
|
|
|
|
* Infinite time actions are valid.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL FiniteTimeAction : public Action
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Get duration in seconds of the action.
|
2015-03-18 20:05:59 +08:00
|
|
|
*
|
|
|
|
* @return The duration in seconds of the action.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getDuration() const { return _duration; }
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Set duration in seconds of the action.
|
2015-03-18 20:05:59 +08:00
|
|
|
*
|
|
|
|
* @param duration In seconds of the action.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setDuration(float duration) { _duration = duration; }
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-16 03:43:22 +08:00
|
|
|
//
|
|
|
|
// Overrides
|
|
|
|
//
|
2014-07-11 10:19:49 +08:00
|
|
|
virtual FiniteTimeAction* reverse() const override
|
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(0);
|
2014-07-11 10:19:49 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-07-18 14:53:00 +08:00
|
|
|
virtual FiniteTimeAction* clone() const override
|
2014-07-11 10:19:49 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(0);
|
2014-07-11 10:19:49 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
2013-06-14 08:25:14 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
FiniteTimeAction() : _duration(0) {}
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual ~FiniteTimeAction() {}
|
2013-11-22 09:06:06 +08:00
|
|
|
|
2014-08-21 15:11:33 +08:00
|
|
|
protected:
|
2015-03-18 20:05:59 +08:00
|
|
|
//! Duration in seconds.
|
2013-06-15 14:03:30 +08:00
|
|
|
float _duration;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-11-22 09:06:06 +08:00
|
|
|
private:
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_DISALLOW_COPY_AND_ASSIGN(FiniteTimeAction);
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
class ActionInterval;
|
|
|
|
class RepeatForever;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/** @class Speed
|
|
|
|
* @brief Changes the speed of an action, making it take longer (speed>1)
|
2016-01-27 09:42:25 +08:00
|
|
|
* or shorter (speed<1) time.
|
2015-03-18 20:05:59 +08:00
|
|
|
* Useful to simulate 'slow motion' or 'fast forward' effect.
|
|
|
|
* @warning This action can't be Sequenceable because it is not an IntervalAction.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL Speed : public Action
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-18 20:05:59 +08:00
|
|
|
/** Create the action and set the speed.
|
|
|
|
*
|
|
|
|
* @param action An action.
|
|
|
|
* @param speed The action speed.
|
|
|
|
*/
|
2013-11-16 21:08:00 +08:00
|
|
|
static Speed* create(ActionInterval* action, float speed);
|
2015-03-18 20:05:59 +08:00
|
|
|
/** Return the speed.
|
|
|
|
*
|
|
|
|
* @return The action speed.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getSpeed() const { return _speed; }
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Alter the speed of the inner function in runtime.
|
2015-03-18 20:05:59 +08:00
|
|
|
*
|
|
|
|
* @param speed Alter the speed of the inner function in runtime.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setSpeed(float speed) { _speed = speed; }
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/** Replace the interior action.
|
|
|
|
*
|
|
|
|
* @param action The new action, it will replace the running action.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void setInnerAction(ActionInterval* action);
|
2015-03-18 20:05:59 +08:00
|
|
|
/** Return the interior action.
|
|
|
|
*
|
|
|
|
* @return The interior action.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
ActionInterval* getInnerAction() const { return _innerAction; }
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-16 03:43:22 +08:00
|
|
|
//
|
|
|
|
// Override
|
|
|
|
//
|
2014-07-18 14:53:00 +08:00
|
|
|
virtual Speed* clone() const override;
|
2013-07-16 03:43:22 +08:00
|
|
|
virtual Speed* reverse() const override;
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void startWithTarget(Node* target) override;
|
2013-07-16 03:43:22 +08:00
|
|
|
virtual void stop() override;
|
2015-01-20 15:41:59 +08:00
|
|
|
/**
|
|
|
|
* @param dt in seconds.
|
|
|
|
*/
|
2013-07-16 03:43:22 +08:00
|
|
|
virtual void step(float dt) override;
|
2015-03-18 20:05:59 +08:00
|
|
|
/** Return true if the action has finished.
|
|
|
|
*
|
|
|
|
* @return Is true if the action has finished.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual bool isDone() const override;
|
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
Speed();
|
2019-07-22 09:38:46 +08:00
|
|
|
virtual ~Speed();
|
2015-03-18 20:05:59 +08:00
|
|
|
/** Initializes the action. */
|
2021-12-25 10:04:45 +08:00
|
|
|
bool initWithAction(ActionInterval* action, float speed);
|
2013-11-22 09:06:06 +08:00
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
protected:
|
2013-06-15 14:03:30 +08:00
|
|
|
float _speed;
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionInterval* _innerAction;
|
2013-11-22 09:06:06 +08:00
|
|
|
|
|
|
|
private:
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_DISALLOW_COPY_AND_ASSIGN(Speed);
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2015-03-23 18:37:28 +08:00
|
|
|
/** @class Follow
|
|
|
|
* @brief Follow is an action that "follows" a node.
|
|
|
|
* Eg:
|
|
|
|
* @code
|
2016-01-18 06:01:03 +08:00
|
|
|
* layer->runAction(Follow::create(hero));
|
2015-03-23 18:37:28 +08:00
|
|
|
* @endcode
|
|
|
|
* Instead of using Camera as a "follower", use this action instead.
|
|
|
|
* @since v0.99.2
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL Follow : public Action
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-07-26 12:04:03 +08:00
|
|
|
/**
|
|
|
|
* Creates the action with a set boundary or with no boundary.
|
|
|
|
*
|
2013-08-01 20:55:43 +08:00
|
|
|
* @param followedNode The node to be followed.
|
2013-07-26 12:04:03 +08:00
|
|
|
* @param rect The boundary. If \p rect is equal to Rect::ZERO, it'll work
|
|
|
|
* with no boundary.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
static Follow* create(Node* followedNode, const Rect& rect = Rect::ZERO);
|
|
|
|
|
2016-04-20 17:25:31 +08:00
|
|
|
/**
|
|
|
|
* Creates the action with a set boundary or with no boundary with offsets.
|
|
|
|
*
|
|
|
|
* @param followedNode The node to be followed.
|
|
|
|
* @param rect The boundary. If \p rect is equal to Rect::ZERO, it'll work
|
|
|
|
* with no boundary.
|
|
|
|
* @param xOffset The horizontal offset from the center of the screen from which the
|
|
|
|
* node is to be followed.It can be positive,negative or zero.If
|
|
|
|
* set to zero the node will be horizontally centered followed.
|
|
|
|
* @param yOffset The vertical offset from the center of the screen from which the
|
|
|
|
* node is to be followed.It can be positive,negative or zero.
|
|
|
|
* If set to zero the node will be vertically centered followed.
|
2021-12-25 10:04:45 +08:00
|
|
|
* If both xOffset and yOffset are set to zero,then the node will be horizontally and vertically centered
|
|
|
|
* followed.
|
2016-04-20 17:25:31 +08:00
|
|
|
*/
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static Follow* createWithOffset(Node* followedNode, float xOffset, float yOffset, const Rect& rect = Rect::ZERO);
|
|
|
|
|
2015-03-23 18:37:28 +08:00
|
|
|
/** Return boundarySet.
|
|
|
|
*
|
|
|
|
* @return Return boundarySet.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
bool isBoundarySet() const { return _boundarySet; }
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Alter behavior - turn on/off boundary.
|
2015-03-23 18:37:28 +08:00
|
|
|
*
|
|
|
|
* @param value Turn on/off boundary.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setBoundarySet(bool value) { _boundarySet = value; }
|
2013-11-22 09:06:06 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// Override
|
|
|
|
//
|
2014-07-18 14:53:00 +08:00
|
|
|
virtual Follow* clone() const override;
|
|
|
|
virtual Follow* reverse() const override;
|
2015-01-20 15:41:59 +08:00
|
|
|
/**
|
|
|
|
* @param dt in seconds.
|
2015-03-19 18:41:11 +08:00
|
|
|
* @js NA
|
2015-01-20 15:41:59 +08:00
|
|
|
*/
|
2013-11-22 09:06:06 +08:00
|
|
|
virtual void step(float dt) override;
|
|
|
|
virtual bool isDone() const override;
|
|
|
|
virtual void stop() override;
|
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
|
|
|
Follow()
|
2021-12-25 10:04:45 +08:00
|
|
|
: _followedNode(nullptr)
|
|
|
|
, _boundarySet(false)
|
|
|
|
, _boundaryFullyCovered(false)
|
|
|
|
, _leftBoundary(0.0)
|
|
|
|
, _rightBoundary(0.0)
|
|
|
|
, _topBoundary(0.0)
|
|
|
|
, _bottomBoundary(0.0)
|
|
|
|
, _offsetX(0.0)
|
|
|
|
, _offsetY(0.0)
|
|
|
|
, _worldRect(Rect::ZERO)
|
2012-04-19 14:35:52 +08:00
|
|
|
{}
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-11-16 21:08:00 +08:00
|
|
|
virtual ~Follow();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-07-26 12:04:03 +08:00
|
|
|
/**
|
|
|
|
* Initializes the action with a set boundary or with no boundary.
|
|
|
|
*
|
2013-08-01 20:55:43 +08:00
|
|
|
* @param followedNode The node to be followed.
|
2013-07-26 12:04:03 +08:00
|
|
|
* @param rect The boundary. If \p rect is equal to Rect::ZERO, it'll work
|
|
|
|
* with no boundary.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
|
|
|
bool initWithTarget(Node* followedNode, const Rect& rect = Rect::ZERO);
|
|
|
|
|
2016-04-20 17:25:31 +08:00
|
|
|
/**
|
|
|
|
* Initializes the action with a set boundary or with no boundary with offsets.
|
|
|
|
*
|
|
|
|
* @param followedNode The node to be followed.
|
|
|
|
* @param rect The boundary. If \p rect is equal to Rect::ZERO, it'll work
|
|
|
|
* with no boundary.
|
|
|
|
* @param xOffset The horizontal offset from the center of the screen from which the
|
|
|
|
* node is to be followed.It can be positive,negative or zero.If
|
|
|
|
* set to zero the node will be horizontally centered followed.
|
|
|
|
* @param yOffset The vertical offset from the center of the screen from which the
|
|
|
|
* node is to be followed.It can be positive,negative or zero.
|
|
|
|
* If set to zero the node will be vertically centered followed.
|
2021-12-25 10:04:45 +08:00
|
|
|
* If both xOffset and yOffset are set to zero,then the node will be horizontally and vertically centered
|
|
|
|
followed.
|
2016-04-20 17:25:31 +08:00
|
|
|
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
bool initWithTargetAndOffset(Node* followedNode, float xOffset, float yOffset, const Rect& rect = Rect::ZERO);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
protected:
|
2015-03-18 20:05:59 +08:00
|
|
|
/** Node to follow. */
|
2021-12-25 10:04:45 +08:00
|
|
|
Node* _followedNode;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/** Whether camera should be limited to certain area. */
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _boundarySet;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/** If screen size is bigger than the boundary - update not needed. */
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _boundaryFullyCovered;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/** Fast access to the screen dimensions. */
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 _halfScreenSize;
|
|
|
|
Vec2 _fullScreenSize;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/** World boundaries. */
|
2013-06-15 14:03:30 +08:00
|
|
|
float _leftBoundary;
|
|
|
|
float _rightBoundary;
|
|
|
|
float _topBoundary;
|
|
|
|
float _bottomBoundary;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2016-04-20 17:25:31 +08:00
|
|
|
/** Horizontal (x) and vertical (y) offset values. */
|
|
|
|
float _offsetX;
|
|
|
|
float _offsetY;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-07-18 14:53:00 +08:00
|
|
|
Rect _worldRect;
|
2013-06-14 08:25:14 +08:00
|
|
|
|
2013-11-22 09:06:06 +08:00
|
|
|
private:
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_DISALLOW_COPY_AND_ASSIGN(Follow);
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2012-06-20 18:07:27 +08:00
|
|
|
// end of actions group
|
|
|
|
/// @}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // __ACTIONS_CCACTION_H__
|