axmol/cocos/2d/CCActionInterval.h

1623 lines
44 KiB
C
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2021-10-24 21:55:48 +08:00
Copyright (c) 2021 Bytedance Inc.
2019-11-23 20:27:39 +08:00
2021-10-24 21:55:48 +08:00
https://adxe.org
2019-11-23 20:27:39 +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 __ACTION_CCINTERVAL_ACTION_H__
#define __ACTION_CCINTERVAL_ACTION_H__
#include <vector>
#include "2d/CCAction.h"
#include "2d/CCAnimation.h"
#include "base/CCProtocols.h"
#include "base/CCVector.h"
NS_CC_BEGIN
class Node;
class SpriteFrame;
class EventCustom;
/**
* @addtogroup actions
* @{
*/
/** @class ActionInterval
@brief An interval action is an action that takes place within a certain period of time.
It has an start time, and a finish time. The finish time is the parameter
duration plus the start time.
These ActionInterval actions have some interesting properties, like:
- They can run normally (default)
- They can run reversed with the reverse method
- They can run with the time altered with the Accelerate, AccelDeccel and Speed actions.
For example, you can simulate a Ping Pong effect running the action normally and
then running it again in Reverse mode.
Example:
@code
auto action = MoveBy::create(1.0f, Vec2::ONE);
auto pingPongAction = Sequence::create(action, action->reverse(), nullptr);
@endcode
*/
class CC_DLL ActionInterval : public FiniteTimeAction
{
public:
/** How many seconds had elapsed since the actions started to run.
*
* @return The seconds had elapsed since the actions started to run.
*/
float getElapsed() { return _elapsed; }
/** Sets the amplitude rate, extension in GridAction
*
* @param amp The amplitude rate.
*/
void setAmplitudeRate(float amp);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/** Gets the amplitude rate, extension in GridAction
*
* @return The amplitude rate.
*/
float getAmplitudeRate();
//
// Overrides
//
virtual bool isDone() const override;
/**
* @param dt in seconds
*/
virtual void step(float dt) override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
virtual ActionInterval* reverse() const override
{
CC_ASSERT(0);
return nullptr;
}
2021-12-25 10:04:45 +08:00
virtual ActionInterval* clone() const override
2019-11-23 20:27:39 +08:00
{
CC_ASSERT(0);
return nullptr;
}
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS :
/** initializes the action */
bool
initWithDuration(float d);
2019-11-23 20:27:39 +08:00
protected:
float _elapsed;
bool _firstTick;
bool _done;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
protected:
2021-12-25 10:04:45 +08:00
bool sendUpdateEventToScript(float dt, Action* actionObject);
2019-11-23 20:27:39 +08:00
};
/** @class Sequence
* @brief Runs actions sequentially, one after another.
*/
class CC_DLL Sequence : public ActionInterval
{
public:
/** Helper constructor to create an array of sequenceable actions.
*
* @return An autoreleased Sequence object.
*/
2021-12-25 10:04:45 +08:00
static Sequence* create(FiniteTimeAction* action1, ...) CC_REQUIRES_NULL_TERMINATION;
2019-11-23 20:27:39 +08:00
/** Helper constructor to create an array of sequenceable actions given an array.
* @code
* When this function bound to the js or lua,the input params changed
* in js :var create(var object1,var object2, ...)
* in lua :local create(local object1,local object2, ...)
* @endcode
*
* @param arrayOfActions An array of sequenceable actions.
* @return An autoreleased Sequence object.
*/
static Sequence* create(const Vector<FiniteTimeAction*>& arrayOfActions);
/** Helper constructor to create an array of sequence-able actions.
*
* @param action1 The first sequenceable action.
* @param args The va_list variable.
* @return An autoreleased Sequence object.
* @js NA
*/
2021-12-25 10:04:45 +08:00
static Sequence* createWithVariableList(FiniteTimeAction* action1, va_list args);
2019-11-23 20:27:39 +08:00
/** Creates the action.
* @param actionOne The first sequenceable action.
* @param actionTwo The second sequenceable action.
* @return An autoreleased Sequence object.
* @js NA
*/
2021-12-25 10:04:45 +08:00
static Sequence* createWithTwoActions(FiniteTimeAction* actionOne, FiniteTimeAction* actionTwo);
2019-11-23 20:27:39 +08:00
//
// Overrides
//
virtual Sequence* clone() const override;
virtual Sequence* reverse() const override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
virtual void stop() override;
virtual bool isDone() const override;
/**
* @param t In seconds.
*/
virtual void update(float t) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : Sequence();
2019-11-23 20:27:39 +08:00
virtual ~Sequence();
/** initializes the action */
2021-12-25 10:04:45 +08:00
bool initWithTwoActions(FiniteTimeAction* pActionOne, FiniteTimeAction* pActionTwo);
2019-11-23 20:27:39 +08:00
bool init(const Vector<FiniteTimeAction*>& arrayOfActions);
protected:
2021-12-25 10:04:45 +08:00
FiniteTimeAction* _actions[2];
2019-11-23 20:27:39 +08:00
float _split;
int _last;
private:
CC_DISALLOW_COPY_AND_ASSIGN(Sequence);
};
/** @class Repeat
* @brief Repeats an action a number of times.
* To repeat an action forever use the RepeatForever action.
*/
class CC_DLL Repeat : public ActionInterval
{
public:
/** Creates a Repeat action. Times is an unsigned integer between 1 and pow(2,30).
*
* @param action The action needs to repeat.
* @param times The repeat times.
* @return An autoreleased Repeat object.
*/
2021-12-25 10:04:45 +08:00
static Repeat* create(FiniteTimeAction* action, unsigned int times);
2019-11-23 20:27:39 +08:00
/** Sets the inner action.
*
* @param action The inner action.
*/
2021-12-25 10:04:45 +08:00
void setInnerAction(FiniteTimeAction* action)
2019-11-23 20:27:39 +08:00
{
if (_innerAction != action)
{
CC_SAFE_RETAIN(action);
CC_SAFE_RELEASE(_innerAction);
_innerAction = action;
}
}
/** Gets the inner action.
*
* @return The inner action.
*/
2021-12-25 10:04:45 +08:00
FiniteTimeAction* getInnerAction() { return _innerAction; }
2019-11-23 20:27:39 +08:00
//
// Overrides
//
virtual Repeat* clone() const override;
virtual Repeat* reverse() const override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
virtual void stop() override;
/**
* @param dt In seconds.
*/
virtual void update(float dt) override;
virtual bool isDone() const override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : Repeat() {}
2019-11-23 20:27:39 +08:00
virtual ~Repeat();
/** initializes a Repeat action. Times is an unsigned integer between 1 and pow(2,30) */
2021-12-25 10:04:45 +08:00
bool initWithAction(FiniteTimeAction* pAction, unsigned int times);
2019-11-23 20:27:39 +08:00
protected:
unsigned int _times;
unsigned int _total;
float _nextDt;
bool _actionInstant;
/** Inner action */
2021-12-25 10:04:45 +08:00
FiniteTimeAction* _innerAction;
2019-11-23 20:27:39 +08:00
private:
CC_DISALLOW_COPY_AND_ASSIGN(Repeat);
};
/** @class RepeatForever
* @brief Repeats an action for ever.
To repeat the an action for a limited number of times use the Repeat action.
* @warning This action can't be Sequenceable because it is not an IntervalAction.
*/
class CC_DLL RepeatForever : public ActionInterval
{
public:
/** Creates the action.
*
* @param action The action need to repeat forever.
* @return An autoreleased RepeatForever object.
*/
2021-12-25 10:04:45 +08:00
static RepeatForever* create(ActionInterval* action);
2019-11-23 20:27:39 +08:00
/** Sets the inner action.
*
* @param action The inner action.
*/
2021-12-25 10:04:45 +08:00
void setInnerAction(ActionInterval* action)
2019-11-23 20:27:39 +08:00
{
if (_innerAction != action)
{
CC_SAFE_RELEASE(_innerAction);
_innerAction = action;
CC_SAFE_RETAIN(_innerAction);
}
}
/** Gets the inner action.
*
* @return The inner action.
*/
2021-12-25 10:04:45 +08:00
ActionInterval* getInnerAction() { return _innerAction; }
2019-11-23 20:27:39 +08:00
//
// Overrides
//
virtual RepeatForever* clone() const override;
virtual RepeatForever* reverse() const override;
virtual void startWithTarget(Node* target) override;
/**
* @param dt In seconds.
*/
virtual void step(float dt) override;
virtual bool isDone() const override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : RepeatForever() : _innerAction(nullptr) {}
2019-11-23 20:27:39 +08:00
virtual ~RepeatForever();
/** initializes the action */
2021-12-25 10:04:45 +08:00
bool initWithAction(ActionInterval* action);
2019-11-23 20:27:39 +08:00
protected:
/** Inner action */
2021-12-25 10:04:45 +08:00
ActionInterval* _innerAction;
2019-11-23 20:27:39 +08:00
private:
CC_DISALLOW_COPY_AND_ASSIGN(RepeatForever);
};
/** @class Spawn
* @brief Spawn a new action immediately
*/
class CC_DLL Spawn : public ActionInterval
{
public:
/** Helper constructor to create an array of spawned actions.
* @code
* When this function bound to the js or lua, the input params changed.
* in js :var create(var object1,var object2, ...)
* in lua :local create(local object1,local object2, ...)
* @endcode
*
* @return An autoreleased Spawn object.
*/
2021-12-25 10:04:45 +08:00
static Spawn* create(FiniteTimeAction* action1, ...) CC_REQUIRES_NULL_TERMINATION;
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
/** Helper constructor to create an array of spawned actions.
2019-11-23 20:27:39 +08:00
*
* @param action1 The first sequenceable action.
* @param args The va_list variable.
* @return An autoreleased Spawn object.
* @js NA
*/
2021-12-25 10:04:45 +08:00
static Spawn* createWithVariableList(FiniteTimeAction* action1, va_list args);
2019-11-23 20:27:39 +08:00
/** Helper constructor to create an array of spawned actions given an array.
*
* @param arrayOfActions An array of spawned actions.
* @return An autoreleased Spawn object.
*/
static Spawn* create(const Vector<FiniteTimeAction*>& arrayOfActions);
/** Creates the Spawn action.
*
* @param action1 The first spawned action.
* @param action2 The second spawned action.
* @return An autoreleased Spawn object.
* @js NA
*/
2021-12-25 10:04:45 +08:00
static Spawn* createWithTwoActions(FiniteTimeAction* action1, FiniteTimeAction* action2);
2019-11-23 20:27:39 +08:00
//
// Overrides
//
virtual Spawn* clone() const override;
virtual Spawn* reverse() const override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
virtual void stop() override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : Spawn();
2019-11-23 20:27:39 +08:00
virtual ~Spawn();
/** initializes the Spawn action with the 2 actions to spawn */
2021-12-25 10:04:45 +08:00
bool initWithTwoActions(FiniteTimeAction* action1, FiniteTimeAction* action2);
2019-11-23 20:27:39 +08:00
bool init(const Vector<FiniteTimeAction*>& arrayOfActions);
protected:
2021-12-25 10:04:45 +08:00
FiniteTimeAction* _one;
FiniteTimeAction* _two;
2019-11-23 20:27:39 +08:00
private:
CC_DISALLOW_COPY_AND_ASSIGN(Spawn);
};
/** @class RotateTo
* @brief Rotates a Node object to a certain angle by modifying it's rotation attribute.
The direction will be decided by the shortest angle.
2021-12-25 10:04:45 +08:00
*/
2019-11-23 20:27:39 +08:00
class CC_DLL RotateTo : public ActionInterval
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action with separate rotation angles.
*
* @param duration Duration time, in seconds.
* @param dstAngleX In degreesCW.
* @param dstAngleY In degreesCW.
* @return An autoreleased RotateTo object.
*/
static RotateTo* create(float duration, float dstAngleX, float dstAngleY);
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action.
*
* @param duration Duration time, in seconds.
* @param dstAngle In degreesCW.
* @return An autoreleased RotateTo object.
*/
static RotateTo* create(float duration, float dstAngle);
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action with 3D rotation angles.
* @param duration Duration time, in seconds.
* @param dstAngle3D A Vec3 angle.
* @return An autoreleased RotateTo object.
*/
static RotateTo* create(float duration, const Vec3& dstAngle3D);
//
// Overrides
//
virtual RotateTo* clone() const override;
virtual RotateTo* reverse() const override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
/**
* @param time In seconds.
*/
virtual void update(float time) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : RotateTo();
2019-11-23 20:27:39 +08:00
virtual ~RotateTo() {}
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* initializes the action
* @param duration in seconds
* @param dstAngleX in degreesCW
* @param dstAngleY in degreesCW
*/
bool initWithDuration(float duration, float dstAngleX, float dstAngleY);
/**
* initializes the action
* @param duration in seconds
*/
bool initWithDuration(float duration, const Vec3& dstAngle3D);
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* calculates the start and diff angles
* @param dstAngle in degreesCW
*/
2021-12-25 10:04:45 +08:00
void calculateAngles(float& startAngle, float& diffAngle, float dstAngle);
2019-11-23 20:27:39 +08:00
protected:
bool _is3D;
Vec3 _dstAngle;
Vec3 _startAngle;
Vec3 _diffAngle;
private:
CC_DISALLOW_COPY_AND_ASSIGN(RotateTo);
};
/** @class RotateBy
* @brief Rotates a Node object clockwise a number of degrees by modifying it's rotation attribute.
2021-12-25 10:04:45 +08:00
*/
2019-11-23 20:27:39 +08:00
class CC_DLL RotateBy : public ActionInterval
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action.
*
* @param duration Duration time, in seconds.
* @param deltaAngle In degreesCW.
* @return An autoreleased RotateBy object.
*/
static RotateBy* create(float duration, float deltaAngle);
/**
* Creates the action with separate rotation angles.
*
* @param duration Duration time, in seconds.
* @param deltaAngleZ_X In degreesCW.
* @param deltaAngleZ_Y In degreesCW.
* @return An autoreleased RotateBy object.
* @warning The physics body contained in Node doesn't support rotate with different x and y angle.
*/
static RotateBy* create(float duration, float deltaAngleZ_X, float deltaAngleZ_Y);
/** Creates the action with 3D rotation angles.
*
* @param duration Duration time, in seconds.
* @param deltaAngle3D A Vec3 angle.
* @return An autoreleased RotateBy object.
*/
static RotateBy* create(float duration, const Vec3& deltaAngle3D);
//
// Override
//
virtual RotateBy* clone() const override;
virtual RotateBy* reverse() const override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
/**
* @param time In seconds.
*/
virtual void update(float time) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : RotateBy();
2019-11-23 20:27:39 +08:00
virtual ~RotateBy() {}
/** initializes the action */
bool initWithDuration(float duration, float deltaAngle);
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* @warning The physics body contained in Node doesn't support rotate with different x and y angle.
* @param deltaAngleZ_X in degreesCW
* @param deltaAngleZ_Y in degreesCW
*/
bool initWithDuration(float duration, float deltaAngleZ_X, float deltaAngleZ_Y);
bool initWithDuration(float duration, const Vec3& deltaAngle3D);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
protected:
bool _is3D;
Vec3 _deltaAngle;
Vec3 _startAngle;
private:
CC_DISALLOW_COPY_AND_ASSIGN(RotateBy);
};
/** @class MoveBy
* @brief Moves a Node object x,y pixels by modifying it's position attribute.
x and y are relative to the position of the object.
Several MoveBy actions can be concurrently called, and the resulting
movement will be the sum of individual movements.
@since v2.1beta2-custom
*/
class CC_DLL MoveBy : public ActionInterval
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action.
*
* @param duration Duration time, in seconds.
* @param deltaPosition The delta distance in 2d, it's a Vec2 type.
* @return An autoreleased MoveBy object.
*/
static MoveBy* create(float duration, const Vec2& deltaPosition);
/**
* Creates the action.
*
* @param duration Duration time, in seconds.
* @param deltaPosition The delta distance in 3d, it's a Vec3 type.
* @return An autoreleased MoveBy object.
*/
static MoveBy* create(float duration, const Vec3& deltaPosition);
//
// Overrides
//
virtual MoveBy* clone() const override;
2021-12-25 10:04:45 +08:00
virtual MoveBy* reverse() const override;
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
/**
* @param time in seconds
*/
virtual void update(float time) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : MoveBy() : _is3D(false) {}
2019-11-23 20:27:39 +08:00
virtual ~MoveBy() {}
/** initializes the action */
bool initWithDuration(float duration, const Vec2& deltaPosition);
bool initWithDuration(float duration, const Vec3& deltaPosition);
protected:
bool _is3D;
Vec3 _positionDelta;
Vec3 _startPosition;
Vec3 _previousPosition;
private:
CC_DISALLOW_COPY_AND_ASSIGN(MoveBy);
};
/** @class MoveTo
2021-12-25 10:04:45 +08:00
* @brief Moves a Node object to the position x,y. x and y are absolute coordinates by modifying it's position
attribute. Several MoveTo actions can be concurrently called, and the resulting movement will be the sum of individual
movements.
2019-11-23 20:27:39 +08:00
@since v2.1beta2-custom
*/
class CC_DLL MoveTo : public MoveBy
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action.
* @param duration Duration time, in seconds.
* @param position The destination position in 2d.
* @return An autoreleased MoveTo object.
*/
static MoveTo* create(float duration, const Vec2& position);
/**
* Creates the action.
* @param duration Duration time, in seconds.
* @param position The destination position in 3d.
* @return An autoreleased MoveTo object.
*/
static MoveTo* create(float duration, const Vec3& position);
//
// Overrides
//
virtual MoveTo* clone() const override;
2021-12-25 10:04:45 +08:00
virtual MoveTo* reverse() const override;
virtual void startWithTarget(Node* target) override;
CC_CONSTRUCTOR_ACCESS : MoveTo() {}
2019-11-23 20:27:39 +08:00
virtual ~MoveTo() {}
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* initializes the action
* @param duration in seconds
*/
bool initWithDuration(float duration, const Vec2& position);
/**
* initializes the action
* @param duration in seconds
*/
bool initWithDuration(float duration, const Vec3& position);
protected:
Vec3 _endPosition;
private:
CC_DISALLOW_COPY_AND_ASSIGN(MoveTo);
};
/** @class SkewTo
* @brief Skews a Node object to given angles by modifying it's skewX and skewY attributes
@since v1.0
*/
class CC_DLL SkewTo : public ActionInterval
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action.
* @param t Duration time, in seconds.
* @param sx Skew x angle.
* @param sy Skew y angle.
* @return An autoreleased SkewTo object.
*/
static SkewTo* create(float t, float sx, float sy);
//
// Overrides
//
virtual SkewTo* clone() const override;
virtual SkewTo* reverse() const override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
/**
* @param time In seconds.
*/
virtual void update(float time) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : SkewTo();
2019-11-23 20:27:39 +08:00
virtual ~SkewTo() {}
/**
* @param t In seconds.
*/
bool initWithDuration(float t, float sx, float sy);
protected:
float _skewX;
float _skewY;
float _startSkewX;
float _startSkewY;
float _endSkewX;
float _endSkewY;
float _deltaX;
float _deltaY;
private:
CC_DISALLOW_COPY_AND_ASSIGN(SkewTo);
};
/** @class SkewBy
* @brief Skews a Node object by skewX and skewY degrees.
@since v1.0
*/
class CC_DLL SkewBy : public SkewTo
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action.
* @param t Duration time, in seconds.
* @param deltaSkewX Skew x delta angle.
* @param deltaSkewY Skew y delta angle.
* @return An autoreleased SkewBy object.
*/
static SkewBy* create(float t, float deltaSkewX, float deltaSkewY);
//
// Overrides
//
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
virtual SkewBy* clone() const override;
2019-11-23 20:27:39 +08:00
virtual SkewBy* reverse() const override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : SkewBy() {}
2019-11-23 20:27:39 +08:00
virtual ~SkewBy() {}
/**
* @param t In seconds.
*/
bool initWithDuration(float t, float sx, float sy);
private:
CC_DISALLOW_COPY_AND_ASSIGN(SkewBy);
};
/** @class ResizeTo
2021-12-25 10:04:45 +08:00
* @brief Resize a Node object to the final size by modifying it's 'size' attribute.
*/
class CC_DLL ResizeTo : public ActionInterval
2019-11-23 20:27:39 +08:00
{
public:
/**
2021-12-25 10:04:45 +08:00
* Creates the action.
* @brief Resize a Node object to the final size by modifying it's 'size' attribute. Works on all nodes where
* setContentSize is effective. But it's mostly useful for nodes where 9-slice is enabled
* @param duration Duration time, in seconds.
* @param final_size The target size to reach
* @return An autoreleased RotateTo object.
*/
2021-10-23 23:27:14 +08:00
static ResizeTo* create(float duration, const Vec2& final_size);
2019-11-23 20:27:39 +08:00
//
// Overrides
//
virtual ResizeTo* clone() const override;
void startWithTarget(cocos2d::Node* target) override;
void update(float time) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : ResizeTo() {}
2019-11-23 20:27:39 +08:00
virtual ~ResizeTo() {}
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/**
2021-12-25 10:04:45 +08:00
* initializes the action
* @param duration in seconds
* @param final_size in Vec2 type
*/
2021-10-23 23:27:14 +08:00
bool initWithDuration(float duration, const Vec2& final_size);
2019-11-23 20:27:39 +08:00
protected:
2021-10-23 23:27:14 +08:00
Vec2 _initialSize;
Vec2 _finalSize;
Vec2 _sizeDelta;
2019-11-23 20:27:39 +08:00
private:
CC_DISALLOW_COPY_AND_ASSIGN(ResizeTo);
};
/** @class ResizeBy
2021-12-25 10:04:45 +08:00
* @brief Resize a Node object by a size. Works on all nodes where setContentSize is effective. But it's mostly useful
* for nodes where 9-slice is enabled
*/
class CC_DLL ResizeBy : public ActionInterval
2019-11-23 20:27:39 +08:00
{
public:
/**
2021-12-25 10:04:45 +08:00
* Creates the action.
*
* @param duration Duration time, in seconds.
* @param deltaSize The delta size.
* @return An autoreleased ResizeBy object.
*/
2021-10-23 23:27:14 +08:00
static ResizeBy* create(float duration, const Vec2& deltaSize);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
//
// Overrides
//
virtual ResizeBy* clone() const override;
2021-12-25 10:04:45 +08:00
virtual ResizeBy* reverse() const override;
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
/**
2021-12-25 10:04:45 +08:00
* @param time in seconds
*/
2019-11-23 20:27:39 +08:00
virtual void update(float time) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : ResizeBy() {}
2019-11-23 20:27:39 +08:00
virtual ~ResizeBy() {}
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
/** initializes the action */
2021-10-23 23:27:14 +08:00
bool initWithDuration(float duration, const Vec2& deltaSize);
2019-11-23 20:27:39 +08:00
protected:
2021-10-23 23:27:14 +08:00
Vec2 _sizeDelta;
Vec2 _startSize;
Vec2 _previousSize;
2019-11-23 20:27:39 +08:00
private:
CC_DISALLOW_COPY_AND_ASSIGN(ResizeBy);
};
/** @class JumpBy
* @brief Moves a Node object simulating a parabolic jump movement by modifying it's position attribute.
2021-12-25 10:04:45 +08:00
*/
2019-11-23 20:27:39 +08:00
class CC_DLL JumpBy : public ActionInterval
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action.
* @param duration Duration time, in seconds.
* @param position The jumping distance.
* @param height The jumping height.
* @param jumps The jumping times.
* @return An autoreleased JumpBy object.
*/
static JumpBy* create(float duration, const Vec2& position, float height, int jumps);
//
// Overrides
//
virtual JumpBy* clone() const override;
virtual JumpBy* reverse() const override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
/**
* @param time In seconds.
*/
virtual void update(float time) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : JumpBy() {}
2019-11-23 20:27:39 +08:00
virtual ~JumpBy() {}
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* initializes the action
* @param duration in seconds
*/
bool initWithDuration(float duration, const Vec2& position, float height, int jumps);
protected:
2021-12-25 10:04:45 +08:00
Vec2 _startPosition;
Vec2 _delta;
float _height;
int _jumps;
Vec2 _previousPos;
2019-11-23 20:27:39 +08:00
private:
CC_DISALLOW_COPY_AND_ASSIGN(JumpBy);
};
/** @class JumpTo
* @brief Moves a Node object to a parabolic position simulating a jump movement by modifying it's position attribute.
2021-12-25 10:04:45 +08:00
*/
2019-11-23 20:27:39 +08:00
class CC_DLL JumpTo : public JumpBy
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action.
* @param duration Duration time, in seconds.
* @param position The jumping destination position.
* @param height The jumping height.
* @param jumps The jumping times.
* @return An autoreleased JumpTo object.
*/
static JumpTo* create(float duration, const Vec2& position, float height, int jumps);
//
// Override
//
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
virtual JumpTo* clone() const override;
virtual JumpTo* reverse() const override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : JumpTo() {}
2019-11-23 20:27:39 +08:00
virtual ~JumpTo() {}
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* initializes the action
* @param duration In seconds.
*/
bool initWithDuration(float duration, const Vec2& position, float height, int jumps);
protected:
Vec2 _endPosition;
private:
CC_DISALLOW_COPY_AND_ASSIGN(JumpTo);
};
/** @struct Bezier configuration structure
*/
2021-12-25 10:04:45 +08:00
typedef struct _ccBezierConfig
{
2019-11-23 20:27:39 +08:00
//! end position of the bezier
Vec2 endPosition;
//! Bezier control point 1
Vec2 controlPoint_1;
//! Bezier control point 2
Vec2 controlPoint_2;
} ccBezierConfig;
/** @class BezierBy
* @brief An action that moves the target with a cubic Bezier curve by a certain distance.
*/
class CC_DLL BezierBy : public ActionInterval
{
public:
/** Creates the action with a duration and a bezier configuration.
* @param t Duration time, in seconds.
* @param c Bezier config.
* @return An autoreleased BezierBy object.
* @code
* When this function bound to js or lua,the input params are changed.
* in js: var create(var t,var table)
* in lua: local create(local t, local table)
* @endcode
*/
static BezierBy* create(float t, const ccBezierConfig& c);
//
// Overrides
//
virtual BezierBy* clone() const override;
virtual BezierBy* reverse() const override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
/**
* @param time In seconds.
*/
virtual void update(float time) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : BezierBy() {}
2019-11-23 20:27:39 +08:00
virtual ~BezierBy() {}
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* initializes the action with a duration and a bezier configuration
* @param t in seconds
*/
bool initWithDuration(float t, const ccBezierConfig& c);
protected:
ccBezierConfig _config;
Vec2 _startPosition;
Vec2 _previousPosition;
private:
CC_DISALLOW_COPY_AND_ASSIGN(BezierBy);
};
/** @class BezierTo
* @brief An action that moves the target with a cubic Bezier curve to a destination point.
@since v0.8.2
*/
class CC_DLL BezierTo : public BezierBy
{
public:
/** Creates the action with a duration and a bezier configuration.
* @param t Duration time, in seconds.
* @param c Bezier config.
* @return An autoreleased BezierTo object.
* @code
* when this function bound to js or lua,the input params are changed
* in js: var create(var t,var table)
* in lua: local create(local t, local table)
* @endcode
*/
static BezierTo* create(float t, const ccBezierConfig& c);
//
// Overrides
//
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
virtual BezierTo* clone() const override;
virtual BezierTo* reverse() const override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : BezierTo() {}
2019-11-23 20:27:39 +08:00
virtual ~BezierTo() {}
/**
* @param t In seconds.
*/
2021-12-25 10:04:45 +08:00
bool initWithDuration(float t, const ccBezierConfig& c);
2019-11-23 20:27:39 +08:00
protected:
ccBezierConfig _toConfig;
private:
CC_DISALLOW_COPY_AND_ASSIGN(BezierTo);
};
/** @class ScaleTo
@brief Scales a Node object to a zoom factor by modifying it's scale attribute.
@warning This action doesn't support "reverse".
@warning The physics body contained in Node doesn't support this action.
*/
class CC_DLL ScaleTo : public ActionInterval
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action with the same scale factor for X and Y.
* @param duration Duration time, in seconds.
* @param s Scale factor of x and y.
* @return An autoreleased ScaleTo object.
*/
static ScaleTo* create(float duration, float s);
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action with and X factor and a Y factor.
* @param duration Duration time, in seconds.
* @param sx Scale factor of x.
* @param sy Scale factor of y.
* @return An autoreleased ScaleTo object.
*/
static ScaleTo* create(float duration, float sx, float sy);
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action with X Y Z factor.
* @param duration Duration time, in seconds.
* @param sx Scale factor of x.
* @param sy Scale factor of y.
* @param sz Scale factor of z.
* @return An autoreleased ScaleTo object.
*/
static ScaleTo* create(float duration, float sx, float sy, float sz);
//
// Overrides
//
virtual ScaleTo* clone() const override;
virtual ScaleTo* reverse() const override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
/**
* @param time In seconds.
*/
virtual void update(float time) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : ScaleTo() {}
2019-11-23 20:27:39 +08:00
virtual ~ScaleTo() {}
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* initializes the action with the same scale factor for X and Y
* @param duration in seconds
*/
bool initWithDuration(float duration, float s);
2021-12-25 10:04:45 +08:00
/**
* initializes the action with and X factor and a Y factor
2019-11-23 20:27:39 +08:00
* @param duration in seconds
*/
bool initWithDuration(float duration, float sx, float sy);
2021-12-25 10:04:45 +08:00
/**
* initializes the action with X Y Z factor
2019-11-23 20:27:39 +08:00
* @param duration in seconds
*/
bool initWithDuration(float duration, float sx, float sy, float sz);
protected:
float _scaleX;
float _scaleY;
float _scaleZ;
float _startScaleX;
float _startScaleY;
float _startScaleZ;
float _endScaleX;
float _endScaleY;
float _endScaleZ;
float _deltaX;
float _deltaY;
float _deltaZ;
private:
CC_DISALLOW_COPY_AND_ASSIGN(ScaleTo);
};
/** @class ScaleBy
* @brief Scales a Node object a zoom factor by modifying it's scale attribute.
@warning The physics body contained in Node doesn't support this action.
*/
class CC_DLL ScaleBy : public ScaleTo
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action with the same scale factor for X and Y.
* @param duration Duration time, in seconds.
* @param s Scale factor of x and y.
* @return An autoreleased ScaleBy object.
*/
static ScaleBy* create(float duration, float s);
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action with and X factor and a Y factor.
* @param duration Duration time, in seconds.
* @param sx Scale factor of x.
* @param sy Scale factor of y.
* @return An autoreleased ScaleBy object.
*/
static ScaleBy* create(float duration, float sx, float sy);
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action with X Y Z factor.
* @param duration Duration time, in seconds.
* @param sx Scale factor of x.
* @param sy Scale factor of y.
* @param sz Scale factor of z.
* @return An autoreleased ScaleBy object.
*/
static ScaleBy* create(float duration, float sx, float sy, float sz);
//
// Overrides
//
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
virtual ScaleBy* clone() const override;
virtual ScaleBy* reverse() const override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : ScaleBy() {}
2019-11-23 20:27:39 +08:00
virtual ~ScaleBy() {}
private:
CC_DISALLOW_COPY_AND_ASSIGN(ScaleBy);
};
/** @class Blink
* @brief Blinks a Node object by modifying it's visible attribute.
2021-12-25 10:04:45 +08:00
*/
2019-11-23 20:27:39 +08:00
class CC_DLL Blink : public ActionInterval
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action.
* @param duration Duration time, in seconds.
* @param blinks Blink times.
* @return An autoreleased Blink object.
*/
static Blink* create(float duration, int blinks);
//
// Overrides
//
virtual Blink* clone() const override;
virtual Blink* reverse() const override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
virtual void stop() override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : Blink() {}
2019-11-23 20:27:39 +08:00
virtual ~Blink() {}
2021-12-25 10:04:45 +08:00
/**
* initializes the action
2019-11-23 20:27:39 +08:00
* @param duration in seconds
*/
bool initWithDuration(float duration, int blinks);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
protected:
int _times;
bool _originalState;
private:
CC_DISALLOW_COPY_AND_ASSIGN(Blink);
};
/** @class FadeTo
2021-12-25 10:04:45 +08:00
* @brief Fades an object that implements the RGBAProtocol protocol. It modifies the opacity from the current value to a
custom one.
2019-11-23 20:27:39 +08:00
@warning This action doesn't support "reverse"
*/
class CC_DLL FadeTo : public ActionInterval
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates an action with duration and opacity.
* @param duration Duration time, in seconds.
* @param opacity A certain opacity, the range is from 0 to 255.
* @return An autoreleased FadeTo object.
*/
static FadeTo* create(float duration, uint8_t opacity);
//
// Overrides
//
virtual FadeTo* clone() const override;
virtual FadeTo* reverse() const override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
/**
* @param time In seconds.
*/
virtual void update(float time) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : FadeTo() {}
2019-11-23 20:27:39 +08:00
virtual ~FadeTo() {}
2021-12-25 10:04:45 +08:00
/**
* initializes the action with duration and opacity
2019-11-23 20:27:39 +08:00
* @param duration in seconds
*/
bool initWithDuration(float duration, uint8_t opacity);
protected:
uint8_t _toOpacity;
uint8_t _fromOpacity;
friend class FadeOut;
friend class FadeIn;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
private:
CC_DISALLOW_COPY_AND_ASSIGN(FadeTo);
};
/** @class FadeIn
* @brief Fades In an object that implements the RGBAProtocol protocol. It modifies the opacity from 0 to 255.
The "reverse" of this action is FadeOut
*/
class CC_DLL FadeIn : public FadeTo
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action.
* @param d Duration time, in seconds.
* @return An autoreleased FadeIn object.
*/
static FadeIn* create(float d);
//
// Overrides
//
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
virtual FadeIn* clone() const override;
virtual FadeTo* reverse() const override;
/**
* @js NA
*/
void setReverseAction(FadeTo* ac);
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : FadeIn() : _reverseAction(nullptr) {}
2019-11-23 20:27:39 +08:00
virtual ~FadeIn() {}
private:
CC_DISALLOW_COPY_AND_ASSIGN(FadeIn);
FadeTo* _reverseAction;
};
/** @class FadeOut
* @brief Fades Out an object that implements the RGBAProtocol protocol. It modifies the opacity from 255 to 0.
The "reverse" of this action is FadeIn
*/
class CC_DLL FadeOut : public FadeTo
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action.
* @param d Duration time, in seconds.
*/
static FadeOut* create(float d);
//
// Overrides
//
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
virtual FadeOut* clone() const override;
2019-11-23 20:27:39 +08:00
virtual FadeTo* reverse() const override;
/**
* @js NA
*/
void setReverseAction(FadeTo* ac);
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : FadeOut() : _reverseAction(nullptr) {}
2019-11-23 20:27:39 +08:00
virtual ~FadeOut() {}
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
private:
CC_DISALLOW_COPY_AND_ASSIGN(FadeOut);
FadeTo* _reverseAction;
};
/** @class TintTo
* @brief Tints a Node that implements the NodeRGB protocol from current tint to a custom one.
@warning This action doesn't support "reverse"
@since v0.7.2
*/
class CC_DLL TintTo : public ActionInterval
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates an action with duration and color.
* @param duration Duration time, in seconds.
* @param red Red Color, from 0 to 255.
* @param green Green Color, from 0 to 255.
* @param blue Blue Color, from 0 to 255.
* @return An autoreleased TintTo object.
*/
static TintTo* create(float duration, uint8_t red, uint8_t green, uint8_t blue);
/**
* Creates an action with duration and color.
* @param duration Duration time, in seconds.
* @param color It's a Color3B type.
* @return An autoreleased TintTo object.
*/
static TintTo* create(float duration, const Color3B& color);
//
// Overrides
//
virtual TintTo* clone() const override;
virtual TintTo* reverse() const override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
/**
* @param time In seconds.
*/
virtual void update(float time) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : TintTo() {}
2019-11-23 20:27:39 +08:00
virtual ~TintTo() {}
/** initializes the action with duration and color */
bool initWithDuration(float duration, uint8_t red, uint8_t green, uint8_t blue);
protected:
Color3B _to;
Color3B _from;
private:
CC_DISALLOW_COPY_AND_ASSIGN(TintTo);
};
/** @class TintBy
@brief Tints a Node that implements the NodeRGB protocol from current tint to a custom one.
@since v0.7.2
*/
class CC_DLL TintBy : public ActionInterval
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates an action with duration and color.
* @param duration Duration time, in seconds.
* @param deltaRed Delta red color.
* @param deltaGreen Delta green color.
* @param deltaBlue Delta blue color.
* @return An autoreleased TintBy object.
*/
static TintBy* create(float duration, int16_t deltaRed, int16_t deltaGreen, int16_t deltaBlue);
//
// Overrides
//
virtual TintBy* clone() const override;
virtual TintBy* reverse() const override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
/**
* @param time In seconds.
*/
virtual void update(float time) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : TintBy() {}
2019-11-23 20:27:39 +08:00
virtual ~TintBy() {}
/** initializes the action with duration and color */
bool initWithDuration(float duration, int16_t deltaRed, int16_t deltaGreen, int16_t deltaBlue);
protected:
int16_t _deltaR;
int16_t _deltaG;
int16_t _deltaB;
int16_t _fromR;
int16_t _fromG;
int16_t _fromB;
private:
CC_DISALLOW_COPY_AND_ASSIGN(TintBy);
};
/** @class DelayTime
* @brief Delays the action a certain amount of seconds.
2021-12-25 10:04:45 +08:00
*/
2019-11-23 20:27:39 +08:00
class CC_DLL DelayTime : public ActionInterval
{
public:
2021-12-25 10:04:45 +08:00
/**
2019-11-23 20:27:39 +08:00
* Creates the action.
* @param d Duration time, in seconds.
* @return An autoreleased DelayTime object.
*/
static DelayTime* create(float d);
//
// Overrides
//
/**
* @param time In seconds.
*/
virtual void update(float time) override;
virtual DelayTime* reverse() const override;
virtual DelayTime* clone() const override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : DelayTime() {}
2019-11-23 20:27:39 +08:00
virtual ~DelayTime() {}
private:
CC_DISALLOW_COPY_AND_ASSIGN(DelayTime);
};
/** @class ReverseTime
* @brief Executes an action in reverse order, from time=duration to time=0
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
@warning Use this action carefully. This action is not
sequenceable. Use it as the default "reversed" method
of your own actions, but using it outside the "reversed"
scope is not recommended.
*/
class CC_DLL ReverseTime : public ActionInterval
{
public:
/** Creates the action.
*
* @param action a certain action.
* @return An autoreleased ReverseTime object.
*/
2021-12-25 10:04:45 +08:00
static ReverseTime* create(FiniteTimeAction* action);
2019-11-23 20:27:39 +08:00
//
// Overrides
//
virtual ReverseTime* reverse() const override;
virtual ReverseTime* clone() const override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
virtual void stop() override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : ReverseTime();
2019-11-23 20:27:39 +08:00
virtual ~ReverseTime();
/** initializes the action */
2021-12-25 10:04:45 +08:00
bool initWithAction(FiniteTimeAction* action);
2019-11-23 20:27:39 +08:00
protected:
2021-12-25 10:04:45 +08:00
FiniteTimeAction* _other;
2019-11-23 20:27:39 +08:00
private:
CC_DISALLOW_COPY_AND_ASSIGN(ReverseTime);
};
class Texture2D;
/** @class Animate
* @brief Animates a sprite given the name of an Animation.
*/
class CC_DLL Animate : public ActionInterval
{
public:
/** Creates the action with an Animation and will restore the original frame when the animation is over.
*
* @param animation A certain animation.
* @return An autoreleased Animate object.
*/
2021-12-25 10:04:45 +08:00
static Animate* create(Animation* animation);
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
/** Sets the Animation object to be animated
*
2019-11-23 20:27:39 +08:00
* @param animation certain animation.
*/
2021-12-25 10:04:45 +08:00
void setAnimation(Animation* animation);
/** returns the Animation object that is being animated
2019-11-23 20:27:39 +08:00
*
* @return Gets the animation object that is being animated.
*/
Animation* getAnimation() { return _animation; }
const Animation* getAnimation() const { return _animation; }
/**
* Gets the index of sprite frame currently displayed.
* @return int the index of sprite frame currently displayed.
*/
int getCurrentFrameIndex() { return _currFrameIndex; }
//
// Overrides
//
virtual Animate* clone() const override;
virtual Animate* reverse() const override;
2021-12-25 10:04:45 +08:00
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
virtual void stop() override;
/**
* @param t In seconds.
*/
virtual void update(float t) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : Animate();
2019-11-23 20:27:39 +08:00
virtual ~Animate();
/** initializes the action with an Animation and will restore the original frame when the animation is over */
2021-12-25 10:04:45 +08:00
bool initWithAnimation(Animation* animation);
2019-11-23 20:27:39 +08:00
protected:
std::vector<float>* _splitTimes = new std::vector<float>;
2021-12-25 10:04:45 +08:00
int _nextFrame = 0;
SpriteFrame* _origFrame = nullptr;
int _currFrameIndex = 0;
unsigned int _executedLoops = 0;
Animation* _animation = nullptr;
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
EventCustom* _frameDisplayedEvent = nullptr;
2019-11-23 20:27:39 +08:00
AnimationFrame::DisplayedEventInfo _frameDisplayedEventInfo;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
private:
CC_DISALLOW_COPY_AND_ASSIGN(Animate);
};
/** @class TargetedAction
* @brief Overrides the target of an action so that it always runs on the target
* specified at action creation rather than the one specified by runAction.
*/
class CC_DLL TargetedAction : public ActionInterval
{
public:
/** Create an action with the specified action and forced target.
2021-12-25 10:04:45 +08:00
*
2019-11-23 20:27:39 +08:00
* @param target The target needs to override.
* @param action The action needs to override.
* @return An autoreleased TargetedAction object.
*/
static TargetedAction* create(Node* target, FiniteTimeAction* action);
/** Sets the target that the action will be forced to run with.
*
* @param forcedTarget The target that the action will be forced to run with.
*/
void setForcedTarget(Node* forcedTarget);
2021-12-25 10:04:45 +08:00
/** returns the target that the action is forced to run with.
2019-11-23 20:27:39 +08:00
*
* @return The target that the action is forced to run with.
*/
Node* getForcedTarget() { return _forcedTarget; }
const Node* getForcedTarget() const { return _forcedTarget; }
//
// Overrides
//
virtual TargetedAction* clone() const override;
2021-12-25 10:04:45 +08:00
virtual TargetedAction* reverse() const override;
virtual void startWithTarget(Node* target) override;
2019-11-23 20:27:39 +08:00
virtual void stop() override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : TargetedAction();
2019-11-23 20:27:39 +08:00
virtual ~TargetedAction();
/** Init an action with the specified action and forced target */
bool initWithTarget(Node* target, FiniteTimeAction* action);
protected:
FiniteTimeAction* _action;
Node* _forcedTarget;
private:
CC_DISALLOW_COPY_AND_ASSIGN(TargetedAction);
};
/**
* @class ActionFloat
* @brief Action used to animate any value in range [from,to] over specified time interval
*/
class CC_DLL ActionFloat : public ActionInterval
{
public:
/**
* Callback function used to report back result
*/
typedef std::function<void(float value)> ActionFloatCallback;
/**
* Creates FloatAction with specified duration, from value, to value and callback to report back
* results
* @param duration of the action
* @param from value to start from
* @param to value to be at the end of the action
* @param callback to report back result
*
* @return An autoreleased ActionFloat object
*/
static ActionFloat* create(float duration, float from, float to, ActionFloatCallback callback);
/**
* Overridden ActionInterval methods
*/
void startWithTarget(Node* target) override;
void update(float delta) override;
ActionFloat* reverse() const override;
ActionFloat* clone() const override;
2021-12-25 10:04:45 +08:00
CC_CONSTRUCTOR_ACCESS : ActionFloat(){};
virtual ~ActionFloat(){};
2019-11-23 20:27:39 +08:00
bool initWithDuration(float duration, float from, float to, ActionFloatCallback callback);
protected:
/* From value */
float _from;
/* To value */
float _to;
/* delta time */
float _delta;
/* Callback to report back results */
ActionFloatCallback _callback;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
private:
CC_DISALLOW_COPY_AND_ASSIGN(ActionFloat);
};
// end of actions group
/// @}
NS_CC_END
2021-12-25 10:04:45 +08:00
#endif //__ACTION_CCINTERVAL_ACTION_H__