2010-11-12 17:26:01 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +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__
|
|
|
|
|
2013-06-04 03:13:24 +08:00
|
|
|
#include <functional>
|
2014-04-27 01:11:22 +08:00
|
|
|
#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
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** @class ActionInstant
|
|
|
|
* @brief Instant actions are immediate actions. They don't have a duration like the IntervalAction actions.
|
|
|
|
**/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL ActionInstant : public FiniteTimeAction //<NSCopying>
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-07-16 03:43:22 +08:00
|
|
|
//
|
|
|
|
// Overrides
|
|
|
|
//
|
2014-07-18 14:53:00 +08:00
|
|
|
virtual ActionInstant* clone() const override
|
2014-07-11 10:19:49 +08:00
|
|
|
{
|
|
|
|
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
|
|
|
/**
|
2015-03-18 20:40:29 +08:00
|
|
|
* @param dt In seconds.
|
2015-01-20 15:41:59 +08:00
|
|
|
*/
|
2013-07-16 03:43:22 +08:00
|
|
|
virtual void step(float dt) override;
|
2015-01-20 15:41:59 +08:00
|
|
|
/**
|
2015-03-18 20:40:29 +08:00
|
|
|
* @param time In seconds.
|
2015-01-20 15:41:59 +08:00
|
|
|
*/
|
2013-07-16 03:43:22 +08:00
|
|
|
virtual void update(float time) override;
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** @class Show
|
|
|
|
* @brief Show the node.
|
|
|
|
**/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL Show : public ActionInstant
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Allocates and initializes the action.
|
|
|
|
*
|
|
|
|
* @return An autoreleased Show object.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
static Show * create();
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-07-16 03:43:22 +08:00
|
|
|
//
|
|
|
|
// Overrides
|
|
|
|
//
|
2015-01-20 15:41:59 +08:00
|
|
|
/**
|
2015-03-18 20:40:29 +08:00
|
|
|
* @param time In seconds.
|
2015-01-20 15:41:59 +08:00
|
|
|
*/
|
2013-07-16 03:43:22 +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;
|
2013-11-22 09:06:06 +08:00
|
|
|
|
2014-08-21 15:11:33 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-22 09:06:06 +08:00
|
|
|
Show(){}
|
|
|
|
virtual ~Show(){}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(Show);
|
2013-07-16 03:43:22 +08:00
|
|
|
};
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** @class Hide
|
|
|
|
* @brief Hide the node.
|
2012-04-18 18:43:45 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL Hide : public ActionInstant
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Allocates and initializes the action.
|
|
|
|
*
|
|
|
|
* @return An autoreleased Hide object.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
static Hide * create();
|
2013-07-16 03:43:22 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// Overrides
|
|
|
|
//
|
2015-01-20 15:41:59 +08:00
|
|
|
/**
|
2015-03-18 20:40:29 +08:00
|
|
|
* @param time In seconds.
|
2015-01-20 15:41:59 +08:00
|
|
|
*/
|
2013-07-16 03:43:22 +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;
|
2013-11-22 09:06:06 +08:00
|
|
|
|
2014-08-21 15:11:33 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-22 09:06:06 +08:00
|
|
|
Hide(){}
|
|
|
|
virtual ~Hide(){}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(Hide);
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** @class ToggleVisibility
|
|
|
|
* @brief Toggles the visibility of a node.
|
2012-04-18 18:43:45 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL ToggleVisibility : public ActionInstant
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Allocates and initializes the action.
|
|
|
|
*
|
|
|
|
* @return An autoreleased ToggleVisibility object.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
static ToggleVisibility * create();
|
2013-07-16 03:43:22 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// Overrides
|
|
|
|
//
|
2015-01-20 15:41:59 +08:00
|
|
|
/**
|
2015-03-18 20:40:29 +08:00
|
|
|
* @param time In seconds.
|
2015-01-20 15:41:59 +08:00
|
|
|
*/
|
2013-07-16 03:43:22 +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;
|
2013-11-22 09:06:06 +08:00
|
|
|
|
2014-08-21 15:11:33 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-22 09:06:06 +08:00
|
|
|
ToggleVisibility(){}
|
|
|
|
virtual ~ToggleVisibility(){}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(ToggleVisibility);
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** @class RemoveSelf
|
|
|
|
* @brief Remove the node.
|
2013-03-25 11:10:51 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL RemoveSelf : public ActionInstant
|
2013-03-25 11:10:51 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-18 20:40:29 +08:00
|
|
|
/** 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);
|
2013-07-16 03:43:22 +08:00
|
|
|
|
2014-07-18 14:53:00 +08:00
|
|
|
//
|
2013-07-16 03:43:22 +08:00
|
|
|
// Override
|
|
|
|
//
|
2015-01-20 15:41:59 +08:00
|
|
|
/**
|
2015-03-18 20:40:29 +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;
|
2014-03-21 13:44:29 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-22 09:06:06 +08:00
|
|
|
RemoveSelf() : _isNeedCleanUp(true){}
|
|
|
|
virtual ~RemoveSelf(){}
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2014-07-18 14:53:00 +08:00
|
|
|
/** init the action */
|
|
|
|
bool init(bool isNeedCleanUp);
|
2013-11-22 09:06:06 +08:00
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
protected:
|
2014-07-18 14:53:00 +08:00
|
|
|
bool _isNeedCleanUp;
|
2013-11-22 09:06:06 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(RemoveSelf);
|
2013-03-25 11:10:51 +08:00
|
|
|
};
|
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** @class FlipX
|
|
|
|
* @brief Flips the sprite horizontally.
|
|
|
|
* @since v0.99.0
|
2012-04-18 18:43:45 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL FlipX : public ActionInstant
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Create the action.
|
|
|
|
*
|
|
|
|
* @param x Flips the sprite horizontally if true.
|
|
|
|
* @return An autoreleased FlipX object.
|
|
|
|
*/
|
2013-07-16 03:43:22 +08:00
|
|
|
static FlipX * create(bool x);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Overrides
|
|
|
|
//
|
2015-01-20 15:41:59 +08:00
|
|
|
/**
|
2015-03-18 20:40:29 +08:00
|
|
|
* @param time In seconds.
|
2015-01-20 15:41:59 +08:00
|
|
|
*/
|
2013-07-16 03:43:22 +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;
|
2014-03-21 13:44:29 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-22 09:06:06 +08:00
|
|
|
FlipX() :_flipX(false) {}
|
|
|
|
virtual ~FlipX() {}
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2013-11-22 09:06:06 +08:00
|
|
|
/** init the action */
|
|
|
|
bool initWithFlipX(bool x);
|
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
protected:
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _flipX;
|
2013-11-22 09:06:06 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(FlipX);
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** @class FlipY
|
|
|
|
* @brief Flips the sprite vertically.
|
|
|
|
* @since v0.99.0
|
2012-04-18 18:43:45 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL FlipY : public ActionInstant
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Create the action.
|
|
|
|
*
|
|
|
|
* @param y Flips the sprite vertically if true.
|
|
|
|
* @return An autoreleased FlipY object.
|
|
|
|
*/
|
2013-07-16 03:43:22 +08:00
|
|
|
static FlipY * create(bool y);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Overrides
|
|
|
|
//
|
2015-01-20 15:41:59 +08:00
|
|
|
/**
|
2015-03-18 20:40:29 +08:00
|
|
|
* @param time In seconds.
|
2015-01-20 15:41:59 +08:00
|
|
|
*/
|
2013-07-16 03:43:22 +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;
|
2014-03-21 13:44:29 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-22 09:06:06 +08:00
|
|
|
FlipY() :_flipY(false) {}
|
|
|
|
virtual ~FlipY() {}
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2013-11-22 09:06:06 +08:00
|
|
|
/** init the action */
|
|
|
|
bool initWithFlipY(bool y);
|
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
protected:
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _flipY;
|
2013-11-22 09:06:06 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(FlipY);
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** @class Place
|
|
|
|
* @brief Places the node in a certain position.
|
2012-04-18 18:43:45 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL Place : public ActionInstant //<NSCopying>
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2012-12-06 18:51:33 +08:00
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Creates a Place action with a position.
|
|
|
|
*
|
|
|
|
* @param pos A certain position.
|
|
|
|
* @return An autoreleased Place object.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
static Place * create(const Vec2& pos);
|
2013-07-16 03:43:22 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// Overrides
|
|
|
|
//
|
2015-01-20 15:41:59 +08:00
|
|
|
/**
|
2015-03-18 20:40:29 +08:00
|
|
|
* @param time In seconds.
|
2015-01-20 15:41:59 +08:00
|
|
|
*/
|
2013-07-16 03:43:22 +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;
|
2014-03-21 13:44:29 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-22 09:06:06 +08:00
|
|
|
Place(){}
|
|
|
|
virtual ~Place(){}
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2013-11-22 09:06:06 +08:00
|
|
|
/** Initializes a Place action with a position */
|
2014-05-15 01:07:09 +08:00
|
|
|
bool initWithPosition(const Vec2& pos);
|
2013-11-22 09:06:06 +08:00
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
protected:
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 _position;
|
2013-11-22 09:06:06 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(Place);
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
|
|
|
|
2013-06-04 03:13:24 +08:00
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** @class CallFunc
|
|
|
|
* @brief Calls a 'callback'.
|
2012-04-18 18:43:45 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL CallFunc : public ActionInstant //<NSCopying>
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-18 20:40:29 +08:00
|
|
|
/** 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.
|
2015-09-22 16:08:23 +08:00
|
|
|
* When this function bound in js or lua ,the input param will be changed.
|
2015-03-18 20:40:29 +08:00
|
|
|
* 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
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
static CallFunc * create(const std::function<void()>& func);
|
2013-06-04 03:13:24 +08:00
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Creates the action with the callback
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
typedef void (Ref::*SEL_CallFunc)();
|
2014-07-18 14:53:00 +08:00
|
|
|
@deprecated Use the std::function API instead.
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
2013-07-16 03:43:22 +08:00
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static CallFunc * create(Ref* target, SEL_CallFunc selector);
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-07-16 03:43:22 +08:00
|
|
|
public:
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Executes the callback.
|
|
|
|
*/
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual void execute();
|
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Get the selector target.
|
|
|
|
*
|
|
|
|
* @return The selector target.
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
inline Ref* getTargetCallback()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _selectorTarget;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Set the selector target.
|
|
|
|
*
|
2015-03-27 12:07:19 +08:00
|
|
|
* @param sel The selector target.
|
2015-03-18 20:40:29 +08:00
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
inline void setTargetCallback(Ref* sel)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
if (sel != _selectorTarget)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
CC_SAFE_RETAIN(sel);
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_selectorTarget);
|
2013-11-16 21:08:00 +08:00
|
|
|
_selectorTarget = sel;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
2013-07-16 03:43:22 +08:00
|
|
|
//
|
|
|
|
// Overrides
|
|
|
|
//
|
2015-01-20 15:41:59 +08:00
|
|
|
/**
|
2015-03-18 20:40:29 +08:00
|
|
|
* @param time In seconds.
|
2015-01-20 15:41:59 +08:00
|
|
|
*/
|
2013-07-16 03:43:22 +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;
|
2014-03-21 13:44:29 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-22 09:06:06 +08:00
|
|
|
CallFunc()
|
2013-12-18 17:47:20 +08:00
|
|
|
: _selectorTarget(nullptr)
|
|
|
|
, _callFunc(nullptr)
|
2013-11-22 09:06:06 +08:00
|
|
|
, _function(nullptr)
|
2013-11-26 05:59:24 +08:00
|
|
|
{
|
|
|
|
}
|
2013-11-22 09:06:06 +08:00
|
|
|
virtual ~CallFunc();
|
|
|
|
|
2014-07-18 14:53:00 +08:00
|
|
|
/** initializes the action with the callback
|
2014-02-20 10:53:49 +08:00
|
|
|
typedef void (Ref::*SEL_CallFunc)();
|
2013-11-22 09:06:06 +08:00
|
|
|
@deprecated Use the std::function API instead.
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Ref* target);
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2014-07-18 14:53:00 +08:00
|
|
|
/** initializes the action with the std::function<void()>
|
2013-11-26 05:59:24 +08:00
|
|
|
* @lua NA
|
2014-07-18 14:53:00 +08:00
|
|
|
*/
|
2013-11-22 09:06:06 +08:00
|
|
|
bool initWithFunction(const std::function<void()>& func);
|
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
protected:
|
2012-04-19 14:35:52 +08:00
|
|
|
/** Target that will be called */
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* _selectorTarget;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
union
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
SEL_CallFunc _callFunc;
|
|
|
|
SEL_CallFuncN _callFuncN;
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
2013-06-04 11:57:32 +08:00
|
|
|
|
|
|
|
/** function that will be called */
|
2014-07-18 14:53:00 +08:00
|
|
|
std::function<void()> _function;
|
2013-11-22 09:06:06 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(CallFunc);
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** @class CallFuncN
|
|
|
|
* @brief Calls a 'callback' with the node as the first argument. N means Node.
|
2015-03-19 18:41:11 +08:00
|
|
|
* @js NA
|
2012-04-18 18:43:45 +08:00
|
|
|
*/
|
2013-08-22 18:16:50 +08:00
|
|
|
class CC_DLL CallFuncN : public CallFunc
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-18 20:40:29 +08:00
|
|
|
/** 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.
|
2015-03-18 20:40:29 +08:00
|
|
|
*
|
2015-09-22 16:08:23 +08:00
|
|
|
* @param func A callback function need to be executed.
|
2015-03-18 20:40:29 +08:00
|
|
|
* @return An autoreleased CallFuncN object.
|
2014-07-18 14:53:00 +08:00
|
|
|
*/
|
2013-06-22 05:58:52 +08:00
|
|
|
static CallFuncN * create(const std::function<void(Node*)>& func);
|
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Creates the action with the callback.
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
typedef void (Ref::*SEL_CallFuncN)(Node*);
|
2013-06-22 05:58:52 +08:00
|
|
|
@deprecated Use the std::function API instead.
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static CallFuncN * create(Ref* target, SEL_CallFuncN selector);
|
2013-07-16 03:43:22 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// Overrides
|
|
|
|
//
|
2014-07-18 14:53:00 +08:00
|
|
|
virtual CallFuncN* clone() const override;
|
2013-07-16 03:43:22 +08:00
|
|
|
virtual void execute() override;
|
2014-03-21 13:44:29 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-22 09:06:06 +08:00
|
|
|
CallFuncN():_functionN(nullptr){}
|
|
|
|
virtual ~CallFuncN(){}
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2013-11-22 09:06:06 +08:00
|
|
|
/** initializes the action with the std::function<void(Node*)> */
|
|
|
|
bool initWithFunction(const std::function<void(Node*)>& func);
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2013-11-22 09:06:06 +08:00
|
|
|
/** initializes the action with the callback
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
typedef void (Ref::*SEL_CallFuncN)(Node*);
|
2013-11-22 09:06:06 +08:00
|
|
|
@deprecated Use the std::function API instead.
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE bool initWithTarget(Ref* target, SEL_CallFuncN selector);
|
2013-11-22 09:06:06 +08:00
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
protected:
|
2013-06-22 05:58:52 +08:00
|
|
|
/** function that will be called with the "sender" as the 1st argument */
|
|
|
|
std::function<void(Node*)> _functionN;
|
2013-11-22 09:06:06 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(CallFuncN);
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
2010-12-23 16:47:29 +08:00
|
|
|
|
2015-03-18 20:40: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.
|
2013-07-24 16:45:11 +08:00
|
|
|
* ND means: Node and Data. Data is void *, so it could be anything.
|
2015-03-19 18:41:11 +08:00
|
|
|
* @js NA
|
2013-07-24 16:45:11 +08:00
|
|
|
*/
|
2013-07-25 15:03:44 +08:00
|
|
|
class CC_DLL __CCCallFuncND : public CallFunc
|
2013-07-24 16:45:11 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-18 20:40:29 +08:00
|
|
|
/** 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.
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static __CCCallFuncND * create(Ref* target, SEL_CallFuncND selector, void* d);
|
2013-07-24 16:45:11 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// Overrides
|
|
|
|
//
|
2014-07-18 14:53:00 +08:00
|
|
|
virtual __CCCallFuncND* clone() const override;
|
2013-07-24 16:45:11 +08:00
|
|
|
virtual void execute() override;
|
|
|
|
|
2014-08-21 15:11:33 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-22 09:06:06 +08:00
|
|
|
__CCCallFuncND() {}
|
|
|
|
virtual ~__CCCallFuncND() {}
|
|
|
|
|
|
|
|
/** initializes the action with the callback and the data to pass as an argument */
|
2014-02-20 10:53:49 +08:00
|
|
|
bool initWithTarget(Ref* target, SEL_CallFuncND selector, void* d);
|
2013-11-22 09:06:06 +08:00
|
|
|
|
2014-08-21 15:11:33 +08:00
|
|
|
protected:
|
2013-07-24 16:45:11 +08:00
|
|
|
SEL_CallFuncND _callFuncND;
|
|
|
|
void* _data;
|
2013-11-22 09:06:06 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(__CCCallFuncND);
|
2013-07-24 16:45:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-03-18 20:40:29 +08:00
|
|
|
/** @class __CCCallFuncO
|
2013-07-24 16:45:11 +08:00
|
|
|
@deprecated Please use CallFuncN instead.
|
2015-03-18 20:40:29 +08:00
|
|
|
@brief Calls a 'callback' with an object as the first argument. O means Object.
|
2013-07-24 16:45:11 +08:00
|
|
|
@since v0.99.5
|
2015-03-19 18:41:11 +08:00
|
|
|
@js NA
|
2013-07-24 16:45:11 +08:00
|
|
|
*/
|
|
|
|
|
2013-08-22 18:16:50 +08:00
|
|
|
class CC_DLL __CCCallFuncO : public CallFunc
|
2013-07-24 16:45:11 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-18 20:40:29 +08:00
|
|
|
/** Creates the action with the callback.
|
|
|
|
typedef void (Ref::*SEL_CallFuncO)(Ref*);
|
|
|
|
*
|
|
|
|
* @param target A certain target.
|
2015-09-22 16:08:23 +08:00
|
|
|
* @param selector The callback need to be executed.
|
2015-03-18 20:40:29 +08:00
|
|
|
* @param object An object as the callback's first argument.
|
|
|
|
* @return An autoreleased __CCCallFuncO object.
|
2013-07-24 16:45:11 +08:00
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static __CCCallFuncO * create(Ref* target, SEL_CallFuncO selector, Ref* object);
|
2013-07-24 16:45:11 +08:00
|
|
|
//
|
|
|
|
// Overrides
|
|
|
|
//
|
2014-07-18 14:53:00 +08:00
|
|
|
virtual __CCCallFuncO* clone() const override;
|
2013-07-24 16:45:11 +08:00
|
|
|
virtual void execute() override;
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* getObject() const;
|
|
|
|
void setObject(Ref* obj);
|
2013-07-24 16:45:11 +08:00
|
|
|
|
2014-08-21 15:11:33 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-22 09:06:06 +08:00
|
|
|
__CCCallFuncO();
|
|
|
|
virtual ~__CCCallFuncO();
|
|
|
|
/** initializes the action with the callback
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
typedef void (Ref::*SEL_CallFuncO)(Ref*);
|
2013-11-22 09:06:06 +08:00
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
bool initWithTarget(Ref* target, SEL_CallFuncO selector, Ref* object);
|
2013-11-22 09:06:06 +08:00
|
|
|
|
2014-08-21 15:11:33 +08:00
|
|
|
protected:
|
2013-07-24 16:45:11 +08:00
|
|
|
/** object to be passed as argument */
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* _object;
|
2013-07-24 16:45:11 +08:00
|
|
|
SEL_CallFuncO _callFuncO;
|
2013-11-22 09:06:06 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(__CCCallFuncO);
|
2013-07-24 16:45:11 +08:00
|
|
|
};
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of actions group
|
|
|
|
/// @}
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2010-11-12 17:26:01 +08:00
|
|
|
#endif //__CCINSTANT_ACTION_H__
|