axmol/cocos/2d/CCActionInstant.h

557 lines
13 KiB
C
Raw Normal View History

2010-11-12 17:26:01 +08:00
/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2014 Chukong Technologies Inc.
2010-11-12 17:26:01 +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.
****************************************************************************/
#ifndef __CCINSTANT_ACTION_H__
#define __CCINSTANT_ACTION_H__
#include <functional>
#include "2d/CCAction.h"
2010-11-12 17:26:01 +08:00
2012-04-18 18:43:45 +08:00
NS_CC_BEGIN
2012-06-20 18:09:11 +08:00
/**
* @addtogroup actions
* @{
*/
/** @class ActionInstant
* @brief Instant actions are immediate actions. They don't have a duration like the IntervalAction actions.
**/
class CC_DLL ActionInstant : public FiniteTimeAction //<NSCopying>
2012-04-18 18:43:45 +08:00
{
public:
//
// Overrides
//
2014-07-18 14:53:00 +08:00
virtual ActionInstant* clone() const override
{
CC_ASSERT(0);
return nullptr;
}
virtual ActionInstant * reverse() const override
{
CC_ASSERT(0);
return nullptr;
}
2013-11-16 21:08:00 +08:00
virtual bool isDone() const override;
2015-01-20 15:41:59 +08:00
/**
* @param dt In seconds.
2015-01-20 15:41:59 +08:00
*/
virtual void step(float dt) override;
2015-01-20 15:41:59 +08:00
/**
* @param time In seconds.
2015-01-20 15:41:59 +08:00
*/
virtual void update(float time) override;
2012-04-18 18:43:45 +08:00
};
/** @class Show
* @brief Show the node.
**/
class CC_DLL Show : public ActionInstant
2012-04-18 18:43:45 +08:00
{
public:
/** Allocates and initializes the action.
*
* @return An autoreleased Show object.
*/
static Show * create();
2012-04-18 18:43:45 +08:00
//
// Overrides
//
2015-01-20 15:41:59 +08:00
/**
* @param time In seconds.
2015-01-20 15:41:59 +08:00
*/
virtual void update(float time) override;
2013-11-16 21:08:00 +08:00
virtual ActionInstant* reverse() const override;
2014-07-18 14:53:00 +08:00
virtual Show* clone() const override;
CC_CONSTRUCTOR_ACCESS:
Show(){}
virtual ~Show(){}
private:
CC_DISALLOW_COPY_AND_ASSIGN(Show);
};
2012-04-18 18:43:45 +08:00
/** @class Hide
* @brief Hide the node.
2012-04-18 18:43:45 +08:00
*/
class CC_DLL Hide : public ActionInstant
2012-04-18 18:43:45 +08:00
{
public:
/** Allocates and initializes the action.
*
* @return An autoreleased Hide object.
*/
static Hide * create();
//
// Overrides
//
2015-01-20 15:41:59 +08:00
/**
* @param time In seconds.
2015-01-20 15:41:59 +08:00
*/
virtual void update(float time) override;
2014-07-18 14:53:00 +08:00
virtual ActionInstant* reverse() const override;
virtual Hide* clone() const override;
CC_CONSTRUCTOR_ACCESS:
Hide(){}
virtual ~Hide(){}
private:
CC_DISALLOW_COPY_AND_ASSIGN(Hide);
2012-04-18 18:43:45 +08:00
};
/** @class ToggleVisibility
* @brief Toggles the visibility of a node.
2012-04-18 18:43:45 +08:00
*/
class CC_DLL ToggleVisibility : public ActionInstant
2012-04-18 18:43:45 +08:00
{
public:
/** Allocates and initializes the action.
*
* @return An autoreleased ToggleVisibility object.
*/
static ToggleVisibility * create();
//
// Overrides
//
2015-01-20 15:41:59 +08:00
/**
* @param time In seconds.
2015-01-20 15:41:59 +08:00
*/
virtual void update(float time) override;
2014-07-18 14:53:00 +08:00
virtual ToggleVisibility* reverse() const override;
virtual ToggleVisibility* clone() const override;
CC_CONSTRUCTOR_ACCESS:
ToggleVisibility(){}
virtual ~ToggleVisibility(){}
private:
CC_DISALLOW_COPY_AND_ASSIGN(ToggleVisibility);
2012-04-18 18:43:45 +08:00
};
/** @class RemoveSelf
* @brief Remove the node.
*/
class CC_DLL RemoveSelf : public ActionInstant
{
public:
/** Create the action.
*
* @param isNeedCleanUp Is need to clean up, the default value is true.
* @return An autoreleased RemoveSelf object.
*/
2014-07-18 14:53:00 +08:00
static RemoveSelf * create(bool isNeedCleanUp = true);
2014-07-18 14:53:00 +08:00
//
// Override
//
2015-01-20 15:41:59 +08:00
/**
* @param time In seconds.
2015-01-20 15:41:59 +08:00
*/
2014-07-18 14:53:00 +08:00
virtual void update(float time) override;
virtual RemoveSelf* clone() const override;
virtual RemoveSelf* reverse() const override;
CC_CONSTRUCTOR_ACCESS:
RemoveSelf() : _isNeedCleanUp(true){}
virtual ~RemoveSelf(){}
2014-07-18 14:53:00 +08:00
/** init the action */
bool init(bool isNeedCleanUp);
protected:
2014-07-18 14:53:00 +08:00
bool _isNeedCleanUp;
private:
CC_DISALLOW_COPY_AND_ASSIGN(RemoveSelf);
};
/** @class FlipX
* @brief Flips the sprite horizontally.
* @since v0.99.0
2012-04-18 18:43:45 +08:00
*/
class CC_DLL FlipX : public ActionInstant
2012-04-18 18:43:45 +08:00
{
public:
/** Create the action.
*
* @param x Flips the sprite horizontally if true.
* @return An autoreleased FlipX object.
*/
static FlipX * create(bool x);
//
// Overrides
//
2015-01-20 15:41:59 +08:00
/**
* @param time In seconds.
2015-01-20 15:41:59 +08:00
*/
virtual void update(float time) override;
2014-07-18 14:53:00 +08:00
virtual FlipX* reverse() const override;
virtual FlipX* clone() const override;
CC_CONSTRUCTOR_ACCESS:
FlipX() :_flipX(false) {}
virtual ~FlipX() {}
/** init the action */
bool initWithFlipX(bool x);
protected:
bool _flipX;
private:
CC_DISALLOW_COPY_AND_ASSIGN(FlipX);
2012-04-18 18:43:45 +08:00
};
/** @class FlipY
* @brief Flips the sprite vertically.
* @since v0.99.0
2012-04-18 18:43:45 +08:00
*/
class CC_DLL FlipY : public ActionInstant
2012-04-18 18:43:45 +08:00
{
public:
/** Create the action.
*
* @param y Flips the sprite vertically if true.
* @return An autoreleased FlipY object.
*/
static FlipY * create(bool y);
//
// Overrides
//
2015-01-20 15:41:59 +08:00
/**
* @param time In seconds.
2015-01-20 15:41:59 +08:00
*/
virtual void update(float time) override;
2014-07-18 14:53:00 +08:00
virtual FlipY* reverse() const override;
virtual FlipY* clone() const override;
CC_CONSTRUCTOR_ACCESS:
FlipY() :_flipY(false) {}
virtual ~FlipY() {}
/** init the action */
bool initWithFlipY(bool y);
protected:
bool _flipY;
private:
CC_DISALLOW_COPY_AND_ASSIGN(FlipY);
2012-04-18 18:43:45 +08:00
};
/** @class Place
* @brief Places the node in a certain position.
2012-04-18 18:43:45 +08:00
*/
class CC_DLL Place : public ActionInstant //<NSCopying>
2012-04-18 18:43:45 +08:00
{
public:
/** Creates a Place action with a position.
*
* @param pos A certain position.
* @return An autoreleased Place object.
*/
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
static Place * create(const Vec2& pos);
//
// Overrides
//
2015-01-20 15:41:59 +08:00
/**
* @param time In seconds.
2015-01-20 15:41:59 +08:00
*/
virtual void update(float time) override;
2014-07-18 14:53:00 +08:00
virtual Place* reverse() const override;
virtual Place* clone() const override;
CC_CONSTRUCTOR_ACCESS:
Place(){}
virtual ~Place(){}
/** Initializes a Place action with a position */
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
bool initWithPosition(const Vec2& pos);
protected:
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec2 _position;
private:
CC_DISALLOW_COPY_AND_ASSIGN(Place);
2012-04-18 18:43:45 +08:00
};
/** @class CallFunc
* @brief Calls a 'callback'.
2012-04-18 18:43:45 +08:00
*/
class CC_DLL CallFunc : public ActionInstant //<NSCopying>
2012-04-18 18:43:45 +08:00
{
public:
/** Creates the action with the callback of type std::function<void()>.
2014-07-18 14:53:00 +08:00
This is the preferred way to create the callback.
* When this function bound in js or lua ,the input param will be changed.
* In js: var create(var func, var this, var [data]) or var create(var func).
* In lua:local create(local funcID).
*
* @param func A callback function need to be excuted.
* @return An autoreleased CallFunc object.
2014-07-18 14:53:00 +08:00
*/
static CallFunc * create(const std::function<void()>& func);
/** Creates the action with the callback
typedef void (Ref::*SEL_CallFunc)();
2014-07-18 14:53:00 +08:00
@deprecated Use the std::function API instead.
* @js NA
* @lua NA
*/
CC_DEPRECATED_ATTRIBUTE static CallFunc * create(Ref* target, SEL_CallFunc selector);
public:
/** Executes the callback.
*/
virtual void execute();
/** Get the selector target.
*
* @return The selector target.
*/
inline Ref* getTargetCallback()
{
return _selectorTarget;
}
/** Set the selector target.
*
2015-03-27 12:07:19 +08:00
* @param sel The selector target.
*/
inline void setTargetCallback(Ref* sel)
{
2013-11-16 21:08:00 +08:00
if (sel != _selectorTarget)
{
2013-11-16 21:08:00 +08:00
CC_SAFE_RETAIN(sel);
CC_SAFE_RELEASE(_selectorTarget);
2013-11-16 21:08:00 +08:00
_selectorTarget = sel;
}
}
//
// Overrides
//
2015-01-20 15:41:59 +08:00
/**
* @param time In seconds.
2015-01-20 15:41:59 +08:00
*/
virtual void update(float time) override;
2014-07-18 14:53:00 +08:00
virtual CallFunc* reverse() const override;
virtual CallFunc* clone() const override;
CC_CONSTRUCTOR_ACCESS:
CallFunc()
: _selectorTarget(nullptr)
, _callFunc(nullptr)
, _function(nullptr)
{
}
virtual ~CallFunc();
2014-07-18 14:53:00 +08:00
/** initializes the action with the callback
typedef void (Ref::*SEL_CallFunc)();
@deprecated Use the std::function API instead.
*/
CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Ref* target);
2014-07-18 14:53:00 +08:00
/** initializes the action with the std::function<void()>
* @lua NA
2014-07-18 14:53:00 +08:00
*/
bool initWithFunction(const std::function<void()>& func);
protected:
/** Target that will be called */
Ref* _selectorTarget;
union
{
SEL_CallFunc _callFunc;
SEL_CallFuncN _callFuncN;
};
/** function that will be called */
2014-07-18 14:53:00 +08:00
std::function<void()> _function;
private:
CC_DISALLOW_COPY_AND_ASSIGN(CallFunc);
2012-04-18 18:43:45 +08:00
};
/** @class CallFuncN
* @brief Calls a 'callback' with the node as the first argument. N means Node.
* @js NA
2012-04-18 18:43:45 +08:00
*/
class CC_DLL CallFuncN : public CallFunc
2012-04-18 18:43:45 +08:00
{
public:
/** Creates the action with the callback of type std::function<void()>.
2014-07-18 14:53:00 +08:00
This is the preferred way to create the callback.
*
* @param func A callback function need to be executed.
* @return An autoreleased CallFuncN object.
2014-07-18 14:53:00 +08:00
*/
static CallFuncN * create(const std::function<void(Node*)>& func);
/** Creates the action with the callback.
typedef void (Ref::*SEL_CallFuncN)(Node*);
@deprecated Use the std::function API instead.
*/
CC_DEPRECATED_ATTRIBUTE static CallFuncN * create(Ref* target, SEL_CallFuncN selector);
//
// Overrides
//
2014-07-18 14:53:00 +08:00
virtual CallFuncN* clone() const override;
virtual void execute() override;
CC_CONSTRUCTOR_ACCESS:
CallFuncN():_functionN(nullptr){}
virtual ~CallFuncN(){}
/** initializes the action with the std::function<void(Node*)> */
bool initWithFunction(const std::function<void(Node*)>& func);
/** initializes the action with the callback
typedef void (Ref::*SEL_CallFuncN)(Node*);
@deprecated Use the std::function API instead.
*/
CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Ref* target, SEL_CallFuncN selector);
protected:
/** function that will be called with the "sender" as the 1st argument */
std::function<void(Node*)> _functionN;
private:
CC_DISALLOW_COPY_AND_ASSIGN(CallFuncN);
2012-04-18 18:43:45 +08:00
};
2010-12-23 16:47:29 +08:00
/** @class __CCCallFuncND
* @deprecated Please use CallFuncN instead.
* @brief Calls a 'callback' with the node as the first argument and the 2nd argument is data.
* ND means: Node and Data. Data is void *, so it could be anything.
* @js NA
*/
class CC_DLL __CCCallFuncND : public CallFunc
{
public:
/** Creates the action with the callback and the data to pass as an argument.
*
* @param target A certain target.
* @param selector The callback need to be excuted.
* @param d Data, is void* type.
* @return An autoreleased __CCCallFuncND object.
*/
CC_DEPRECATED_ATTRIBUTE static __CCCallFuncND * create(Ref* target, SEL_CallFuncND selector, void* d);
//
// Overrides
//
2014-07-18 14:53:00 +08:00
virtual __CCCallFuncND* clone() const override;
virtual void execute() override;
CC_CONSTRUCTOR_ACCESS:
__CCCallFuncND() {}
virtual ~__CCCallFuncND() {}
/** initializes the action with the callback and the data to pass as an argument */
bool initWithTarget(Ref* target, SEL_CallFuncND selector, void* d);
protected:
SEL_CallFuncND _callFuncND;
void* _data;
private:
CC_DISALLOW_COPY_AND_ASSIGN(__CCCallFuncND);
};
/** @class __CCCallFuncO
@deprecated Please use CallFuncN instead.
@brief Calls a 'callback' with an object as the first argument. O means Object.
@since v0.99.5
@js NA
*/
class CC_DLL __CCCallFuncO : public CallFunc
{
public:
/** Creates the action with the callback.
typedef void (Ref::*SEL_CallFuncO)(Ref*);
*
* @param target A certain target.
* @param selector The callback need to be executed.
* @param object An object as the callback's first argument.
* @return An autoreleased __CCCallFuncO object.
*/
CC_DEPRECATED_ATTRIBUTE static __CCCallFuncO * create(Ref* target, SEL_CallFuncO selector, Ref* object);
//
// Overrides
//
2014-07-18 14:53:00 +08:00
virtual __CCCallFuncO* clone() const override;
virtual void execute() override;
Ref* getObject() const;
void setObject(Ref* obj);
CC_CONSTRUCTOR_ACCESS:
__CCCallFuncO();
virtual ~__CCCallFuncO();
/** initializes the action with the callback
typedef void (Ref::*SEL_CallFuncO)(Ref*);
*/
bool initWithTarget(Ref* target, SEL_CallFuncO selector, Ref* object);
protected:
/** object to be passed as argument */
Ref* _object;
SEL_CallFuncO _callFuncO;
private:
CC_DISALLOW_COPY_AND_ASSIGN(__CCCallFuncO);
};
2012-06-20 18:09:11 +08:00
// end of actions group
/// @}
2012-04-18 18:43:45 +08:00
NS_CC_END
2010-11-12 17:26:01 +08:00
#endif //__CCINSTANT_ACTION_H__