2010-11-12 17:26:01 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 10:59:01 +08:00
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2011-07-01 15:08:23 +08:00
|
|
|
Copyright (c) 2011 Zynga 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__
|
|
|
|
|
2011-06-21 10:18:43 +08:00
|
|
|
#include <string>
|
2010-11-12 17:26:01 +08:00
|
|
|
#include "CCAction.h"
|
|
|
|
|
|
|
|
namespace cocos2d {
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
|
|
|
@brief Instant actions are immediate actions. They don't have a duration like
|
2010-08-05 17:22:47 +08:00
|
|
|
the CCIntervalAction actions.
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCActionInstant : public CCFiniteTimeAction //<NSCopying>
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
public:
|
2010-12-22 15:43:54 +08:00
|
|
|
CCActionInstant();
|
|
|
|
virtual ~CCActionInstant(){}
|
2010-09-29 12:03:21 +08:00
|
|
|
// CCAction methods
|
2011-03-07 17:11:57 +08:00
|
|
|
virtual CCObject* copyWithZone(CCZone *pZone);
|
2010-08-05 17:22:47 +08:00
|
|
|
virtual bool isDone(void);
|
|
|
|
virtual void step(ccTime dt);
|
|
|
|
virtual void update(ccTime time);
|
|
|
|
//CCFiniteTimeAction method
|
2010-09-28 16:18:05 +08:00
|
|
|
virtual CCFiniteTimeAction * reverse(void);
|
2010-08-05 17:22:47 +08:00
|
|
|
};
|
|
|
|
|
2010-09-29 09:44:57 +08:00
|
|
|
/** @brief Show the node
|
2010-08-05 17:22:47 +08:00
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCShow : public CCActionInstant
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCShow(){}
|
|
|
|
virtual ~CCShow(){}
|
2010-09-29 12:03:21 +08:00
|
|
|
//super methods
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2010-11-12 17:26:01 +08:00
|
|
|
virtual CCFiniteTimeAction * reverse(void);
|
2011-08-25 19:04:29 +08:00
|
|
|
virtual CCObject* copyWithZone(CCZone *pZone);
|
2010-11-12 17:26:01 +08:00
|
|
|
public:
|
|
|
|
//override static method
|
|
|
|
/** Allocates and initializes the action */
|
|
|
|
static CCShow * action();
|
2010-08-05 17:22:47 +08:00
|
|
|
};
|
|
|
|
|
2011-08-25 19:04:29 +08:00
|
|
|
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
|
|
|
@brief Hide the node
|
2010-08-05 17:22:47 +08:00
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCHide : public CCActionInstant
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCHide(){}
|
|
|
|
virtual ~CCHide(){}
|
2010-09-29 12:03:21 +08:00
|
|
|
//super methods
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2010-11-12 17:26:01 +08:00
|
|
|
virtual CCFiniteTimeAction * reverse(void);
|
2011-08-25 19:04:29 +08:00
|
|
|
virtual CCObject* copyWithZone(CCZone *pZone);
|
2010-11-12 17:26:01 +08:00
|
|
|
public:
|
|
|
|
//override static method
|
|
|
|
/** Allocates and initializes the action */
|
|
|
|
static CCHide * action();
|
2010-08-05 17:22:47 +08:00
|
|
|
};
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/** @brief Toggles the visibility of a node
|
2010-08-05 17:22:47 +08:00
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCToggleVisibility : public CCActionInstant
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCToggleVisibility(){}
|
|
|
|
virtual ~CCToggleVisibility(){}
|
|
|
|
//super method
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2010-11-12 17:26:01 +08:00
|
|
|
public:
|
|
|
|
//override static method
|
|
|
|
/** Allocates and initializes the action */
|
2010-08-12 16:19:09 +08:00
|
|
|
static CCToggleVisibility * action();
|
2010-08-05 17:22:47 +08:00
|
|
|
};
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
|
|
|
@brief Flips the sprite horizontally
|
2010-08-05 17:22:47 +08:00
|
|
|
@since v0.99.0
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCFlipX : public CCActionInstant
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
public:
|
2011-04-01 16:06:53 +08:00
|
|
|
CCFlipX()
|
|
|
|
:m_bFlipX(false)
|
|
|
|
{}
|
2010-08-05 17:22:47 +08:00
|
|
|
virtual ~CCFlipX(){}
|
|
|
|
|
2010-09-29 17:39:45 +08:00
|
|
|
/** create the action */
|
2010-08-05 17:22:47 +08:00
|
|
|
static CCFlipX * actionWithFlipX(bool x);
|
2010-09-29 17:39:45 +08:00
|
|
|
/** init the action */
|
2010-09-04 12:02:52 +08:00
|
|
|
bool initWithFlipX(bool x);
|
2010-09-29 12:03:21 +08:00
|
|
|
//super methods
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2010-11-12 17:26:01 +08:00
|
|
|
virtual CCFiniteTimeAction * reverse(void);
|
2011-03-07 17:11:57 +08:00
|
|
|
virtual CCObject* copyWithZone(CCZone *pZone);
|
2010-11-12 17:26:01 +08:00
|
|
|
|
2010-08-05 17:22:47 +08:00
|
|
|
protected:
|
|
|
|
bool m_bFlipX;
|
|
|
|
};
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
|
|
|
@brief Flips the sprite vertically
|
2010-08-05 17:22:47 +08:00
|
|
|
@since v0.99.0
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCFlipY : public CCActionInstant
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
public:
|
2011-04-01 16:06:53 +08:00
|
|
|
CCFlipY()
|
|
|
|
:m_bFlipY(false)
|
|
|
|
{}
|
2010-08-05 17:22:47 +08:00
|
|
|
virtual ~CCFlipY(){}
|
2010-09-29 17:39:45 +08:00
|
|
|
|
|
|
|
/** create the action */
|
2010-08-05 17:22:47 +08:00
|
|
|
static CCFlipY * actionWithFlipY(bool y);
|
2010-09-29 17:39:45 +08:00
|
|
|
/** init the action */
|
2010-09-04 12:02:52 +08:00
|
|
|
bool initWithFlipY(bool y);
|
2010-09-29 12:03:21 +08:00
|
|
|
//super methods
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2010-11-12 17:26:01 +08:00
|
|
|
virtual CCFiniteTimeAction * reverse(void);
|
2011-03-07 17:11:57 +08:00
|
|
|
virtual CCObject* copyWithZone(CCZone *pZone);
|
2010-08-05 17:22:47 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool m_bFlipY;
|
|
|
|
};
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/** @brief Places the node in a certain position
|
2010-08-05 17:22:47 +08:00
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCPlace : public CCActionInstant //<NSCopying>
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCPlace(){}
|
|
|
|
virtual ~CCPlace(){}
|
|
|
|
/** creates a Place action with a position */
|
2011-08-17 21:19:57 +08:00
|
|
|
static CCPlace * actionWithPosition(const CCPoint& pos);
|
2010-08-05 17:22:47 +08:00
|
|
|
/** Initializes a Place action with a position */
|
2011-08-17 21:19:57 +08:00
|
|
|
bool initWithPosition(const CCPoint& pos);
|
2010-09-29 12:03:21 +08:00
|
|
|
//super methods
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2011-03-07 17:11:57 +08:00
|
|
|
virtual CCObject* copyWithZone(CCZone *pZone);
|
2010-08-05 17:22:47 +08:00
|
|
|
protected:
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint m_tPosition;
|
2010-08-05 17:22:47 +08:00
|
|
|
};
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/** @brief Calls a 'callback'
|
2010-08-05 17:22:47 +08:00
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCCallFunc : public CCActionInstant //<NSCopying>
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCCallFunc()
|
2011-06-10 17:51:37 +08:00
|
|
|
: m_pSelectorTarget(NULL)
|
2011-06-20 17:31:38 +08:00
|
|
|
, m_scriptFuncName("")
|
2011-08-17 11:18:58 +08:00
|
|
|
, m_pCallFunc(NULL)
|
|
|
|
|
2011-06-10 17:51:37 +08:00
|
|
|
{
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
|
|
|
virtual ~CCCallFunc()
|
|
|
|
{
|
2010-11-12 17:26:01 +08:00
|
|
|
if (m_pSelectorTarget)
|
|
|
|
{
|
2012-02-02 17:46:45 +08:00
|
|
|
m_pSelectorTarget->release();
|
2010-09-30 11:57:31 +08:00
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
}
|
2010-09-29 17:39:45 +08:00
|
|
|
/** creates the action with the callback
|
|
|
|
|
2012-01-08 21:03:16 +08:00
|
|
|
typedef void (CCObject::*SEL_CallFunc)();
|
2010-09-29 17:39:45 +08:00
|
|
|
*/
|
2012-01-08 21:03:16 +08:00
|
|
|
static CCCallFunc * actionWithTarget(CCObject* pSelectorTarget, SEL_CallFunc selector);
|
2011-06-20 17:31:38 +08:00
|
|
|
static CCCallFunc* actionWithScriptFuncName(const char* pszFuncName);
|
2010-09-29 17:39:45 +08:00
|
|
|
/** initializes the action with the callback
|
|
|
|
|
2012-01-08 21:03:16 +08:00
|
|
|
typedef void (CCObject::*SEL_CallFunc)();
|
2010-09-29 17:39:45 +08:00
|
|
|
*/
|
2012-01-08 21:03:16 +08:00
|
|
|
virtual bool initWithTarget(CCObject* pSelectorTarget);
|
2011-06-20 17:31:38 +08:00
|
|
|
virtual bool initWithScriptFuncName(const char* pszFuncName);
|
2010-09-29 17:39:45 +08:00
|
|
|
/** executes the callback */
|
2010-08-05 17:22:47 +08:00
|
|
|
virtual void execute();
|
2010-09-29 12:03:21 +08:00
|
|
|
//super methods
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2011-08-17 21:19:57 +08:00
|
|
|
CCObject * copyWithZone(CCZone *pZone);
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2011-06-20 17:31:38 +08:00
|
|
|
void registerScriptFunction(const char* pszFunctionName);
|
|
|
|
|
2012-01-08 21:03:16 +08:00
|
|
|
inline CCObject* getTargetCallback()
|
2011-07-01 15:08:23 +08:00
|
|
|
{
|
|
|
|
return m_pSelectorTarget;
|
|
|
|
}
|
|
|
|
|
2012-01-08 21:03:16 +08:00
|
|
|
inline void setTargetCallback(CCObject* pSel)
|
2011-07-01 15:08:23 +08:00
|
|
|
{
|
|
|
|
if (pSel != m_pSelectorTarget)
|
|
|
|
{
|
|
|
|
if (m_pSelectorTarget)
|
|
|
|
{
|
2012-01-08 21:03:16 +08:00
|
|
|
m_pSelectorTarget->release();
|
2011-07-01 15:08:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
m_pSelectorTarget = pSel;
|
|
|
|
|
|
|
|
if (m_pSelectorTarget)
|
|
|
|
{
|
2012-01-08 21:03:16 +08:00
|
|
|
m_pSelectorTarget->retain();
|
2011-07-01 15:08:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-05 17:22:47 +08:00
|
|
|
protected:
|
2011-07-01 15:08:23 +08:00
|
|
|
/** Target that will be called */
|
2012-01-08 21:03:16 +08:00
|
|
|
CCObject* m_pSelectorTarget;
|
2011-07-01 15:08:23 +08:00
|
|
|
/** the script function name to call back */
|
2011-06-20 17:31:38 +08:00
|
|
|
std::string m_scriptFuncName;
|
|
|
|
|
2010-08-05 17:22:47 +08:00
|
|
|
union
|
|
|
|
{
|
|
|
|
SEL_CallFunc m_pCallFunc;
|
|
|
|
SEL_CallFuncN m_pCallFuncN;
|
|
|
|
SEL_CallFuncND m_pCallFuncND;
|
2010-12-23 16:47:29 +08:00
|
|
|
SEL_CallFuncO m_pCallFuncO;
|
2010-11-12 17:26:01 +08:00
|
|
|
};
|
2010-08-05 17:22:47 +08:00
|
|
|
};
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
|
|
|
@brief Calls a 'callback' with the node as the first argument
|
2010-08-05 17:22:47 +08:00
|
|
|
N means Node
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCCallFuncN : public CCCallFunc
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCCallFuncN(){}
|
|
|
|
virtual ~CCCallFuncN(){}
|
2010-09-29 17:39:45 +08:00
|
|
|
/** creates the action with the callback
|
|
|
|
|
2012-01-08 21:03:16 +08:00
|
|
|
typedef void (CCObject::*SEL_CallFuncN)(CCNode*);
|
2010-09-29 17:39:45 +08:00
|
|
|
*/
|
2012-01-08 21:03:16 +08:00
|
|
|
static CCCallFuncN * actionWithTarget(CCObject* pSelectorTarget, SEL_CallFuncN selector);
|
2011-06-20 17:31:38 +08:00
|
|
|
static CCCallFuncN* actionWithScriptFuncName(const char* pszFuncName);
|
2010-09-29 17:39:45 +08:00
|
|
|
/** initializes the action with the callback
|
|
|
|
|
2012-01-08 21:03:16 +08:00
|
|
|
typedef void (CCObject::*SEL_CallFuncN)(CCNode*);
|
2010-09-29 17:39:45 +08:00
|
|
|
*/
|
2012-01-08 21:03:16 +08:00
|
|
|
virtual bool initWithTarget(CCObject* pSelectorTarget, SEL_CallFuncN selector);
|
2010-09-29 12:03:21 +08:00
|
|
|
// super methods
|
2011-03-07 17:11:57 +08:00
|
|
|
virtual CCObject* copyWithZone(CCZone *pZone);
|
2010-08-05 17:22:47 +08:00
|
|
|
virtual void execute();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
|
|
|
@brief Calls a 'callback' with the node as the first argument and the 2nd argument is data
|
2010-08-05 17:22:47 +08:00
|
|
|
* ND means: Node and Data. Data is void *, so it could be anything.
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCCallFuncND : public CCCallFuncN
|
2010-08-05 17:22:47 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** creates the action with the callback and the data to pass as an argument */
|
2012-01-08 21:03:16 +08:00
|
|
|
static CCCallFuncND * actionWithTarget(CCObject* pSelectorTarget, SEL_CallFuncND selector, void* d);
|
2011-06-20 17:31:38 +08:00
|
|
|
static CCCallFuncND* actionWithScriptFuncName(const char* pszFuncName, void *d);
|
2010-08-05 17:22:47 +08:00
|
|
|
/** initializes the action with the callback and the data to pass as an argument */
|
2012-01-08 21:03:16 +08:00
|
|
|
virtual bool initWithTarget(CCObject* pSelectorTarget, SEL_CallFuncND selector, void* d);
|
2010-09-29 12:03:21 +08:00
|
|
|
// super methods
|
2011-03-07 17:11:57 +08:00
|
|
|
virtual CCObject* copyWithZone(CCZone *pZone);
|
2010-08-05 17:22:47 +08:00
|
|
|
virtual void execute();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void *m_pData;
|
|
|
|
};
|
|
|
|
|
2011-03-19 10:59:01 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief Calls a 'callback' with an object as the first argument.
|
|
|
|
O means Object.
|
|
|
|
@since v0.99.5
|
|
|
|
*/
|
|
|
|
class CC_DLL CCCallFuncO : public CCCallFunc
|
|
|
|
{
|
|
|
|
public:
|
2010-12-23 16:47:29 +08:00
|
|
|
CCCallFuncO();
|
|
|
|
virtual ~CCCallFuncO();
|
|
|
|
/** creates the action with the callback
|
|
|
|
|
2012-01-08 21:03:16 +08:00
|
|
|
typedef void (CCObject::*SEL_CallFuncO)(CCObject*);
|
2010-12-23 16:47:29 +08:00
|
|
|
*/
|
2012-01-08 21:03:16 +08:00
|
|
|
static CCCallFuncO * actionWithTarget(CCObject* pSelectorTarget, SEL_CallFuncO selector, CCObject* pObject);
|
2011-06-20 17:31:38 +08:00
|
|
|
static CCCallFuncO* actionWithScriptFuncName(const char* pszFuncName);
|
2010-12-23 16:47:29 +08:00
|
|
|
/** initializes the action with the callback
|
|
|
|
|
2012-01-08 21:03:16 +08:00
|
|
|
typedef void (CCObject::*SEL_CallFuncO)(CCObject*);
|
2010-12-23 16:47:29 +08:00
|
|
|
*/
|
2012-01-08 21:03:16 +08:00
|
|
|
virtual bool initWithTarget(CCObject* pSelectorTarget, SEL_CallFuncO selector, CCObject* pObject);
|
2010-12-23 16:47:29 +08:00
|
|
|
// super methods
|
2011-03-07 17:11:57 +08:00
|
|
|
virtual CCObject* copyWithZone(CCZone *pZone);
|
2011-03-19 10:59:01 +08:00
|
|
|
virtual void execute();
|
|
|
|
|
2011-07-01 15:08:23 +08:00
|
|
|
inline CCObject* getObject()
|
|
|
|
{
|
|
|
|
return m_pObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void setObject(CCObject* pObj)
|
|
|
|
{
|
|
|
|
if (pObj != m_pObject)
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(m_pObject);
|
|
|
|
m_pObject = pObj;
|
|
|
|
CC_SAFE_RETAIN(m_pObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-19 10:59:01 +08:00
|
|
|
protected:
|
2011-07-01 15:08:23 +08:00
|
|
|
/** object to be passed as argument */
|
2011-03-19 10:59:01 +08:00
|
|
|
CCObject* m_pObject;
|
|
|
|
};
|
2010-12-23 16:47:29 +08:00
|
|
|
|
2010-11-12 17:26:01 +08:00
|
|
|
}
|
2010-08-05 17:22:47 +08:00
|
|
|
|
2010-11-12 17:26:01 +08:00
|
|
|
#endif //__CCINSTANT_ACTION_H__
|