2010-08-05 17:22:47 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
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 "CCAction.h"
|
|
|
|
#include "selector_protocol.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.
|
|
|
|
*/
|
|
|
|
class CCX_DLL CCInstantAction : public CCFiniteTimeAction //<NSCopying>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCInstantAction();
|
|
|
|
virtual ~CCInstantAction(){}
|
|
|
|
// CCAction method
|
|
|
|
virtual NSObject* copyWithZone(NSZone *pZone);
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/** Show the node
|
|
|
|
*/
|
|
|
|
class CCX_DLL CCShow : public CCInstantAction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCShow(){}
|
|
|
|
virtual ~CCShow(){}
|
|
|
|
//super method
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2010-08-05 17:22:47 +08:00
|
|
|
virtual CCFiniteTimeAction * reverse(void);
|
2010-08-12 16:19:09 +08:00
|
|
|
public:
|
|
|
|
//override static method
|
|
|
|
static CCShow * action();
|
2010-08-05 17:22:47 +08:00
|
|
|
};
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
|
|
|
@brief Hide the node
|
2010-08-05 17:22:47 +08:00
|
|
|
*/
|
|
|
|
class CCX_DLL CCHide : public CCInstantAction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCHide(){}
|
|
|
|
virtual ~CCHide(){}
|
|
|
|
//super method
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2010-08-05 17:22:47 +08:00
|
|
|
virtual CCFiniteTimeAction * reverse(void);
|
2010-08-12 16:19:09 +08:00
|
|
|
public:
|
|
|
|
//override static method
|
|
|
|
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
|
|
|
*/
|
|
|
|
class CCX_DLL CCToggleVisibility : public CCInstantAction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCToggleVisibility(){}
|
|
|
|
virtual ~CCToggleVisibility(){}
|
|
|
|
//super method
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2010-08-12 16:19:09 +08:00
|
|
|
public:
|
|
|
|
//override static method
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
class CCX_DLL CCFlipX : public CCInstantAction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCFlipX(){}
|
|
|
|
virtual ~CCFlipX(){}
|
|
|
|
|
|
|
|
static CCFlipX * actionWithFlipX(bool x);
|
2010-09-04 12:02:52 +08:00
|
|
|
bool initWithFlipX(bool x);
|
2010-08-05 17:22:47 +08:00
|
|
|
//super method
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2010-08-05 17:22:47 +08:00
|
|
|
virtual CCFiniteTimeAction * reverse(void);
|
|
|
|
virtual NSObject* copyWithZone(NSZone *pZone);
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
class CCX_DLL CCFlipY : public CCInstantAction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCFlipY(){}
|
|
|
|
virtual ~CCFlipY(){}
|
|
|
|
|
|
|
|
static CCFlipY * actionWithFlipY(bool y);
|
2010-09-04 12:02:52 +08:00
|
|
|
bool initWithFlipY(bool y);
|
2010-08-05 17:22:47 +08:00
|
|
|
//super method
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2010-08-05 17:22:47 +08:00
|
|
|
virtual CCFiniteTimeAction * reverse(void);
|
|
|
|
virtual NSObject* copyWithZone(NSZone *pZone);
|
|
|
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
class CCX_DLL CCPlace : public CCInstantAction //<NSCopying>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCPlace(){}
|
|
|
|
virtual ~CCPlace(){}
|
|
|
|
/** creates a Place action with a position */
|
|
|
|
static CCPlace * actionWithPosition(CGPoint pos);
|
|
|
|
/** Initializes a Place action with a position */
|
2010-09-04 12:02:52 +08:00
|
|
|
bool initWithPosition(CGPoint pos);
|
2010-08-05 17:22:47 +08:00
|
|
|
//super method
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2010-08-05 17:22:47 +08:00
|
|
|
virtual NSObject* copyWithZone(NSZone *pZone);
|
|
|
|
protected:
|
|
|
|
CGPoint m_tPosition;
|
|
|
|
};
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/** @brief Calls a 'callback'
|
2010-08-05 17:22:47 +08:00
|
|
|
*/
|
|
|
|
class CCX_DLL CCCallFunc : public CCInstantAction //<NSCopying>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCCallFunc()
|
|
|
|
{
|
|
|
|
m_pCallFunc = NULL;
|
|
|
|
m_pSelectorTarget = NULL;
|
|
|
|
}
|
|
|
|
virtual ~CCCallFunc()
|
|
|
|
{
|
|
|
|
}
|
2010-09-28 16:18:05 +08:00
|
|
|
/** creates the action with the callback */
|
2010-08-05 17:22:47 +08:00
|
|
|
static CCCallFunc * actionWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFunc selector);
|
2010-09-28 16:18:05 +08:00
|
|
|
/** initializes the action with the callback */
|
2010-09-04 12:02:52 +08:00
|
|
|
virtual bool initWithTarget(SelectorProtocol* pSelectorTarget);
|
2010-09-28 16:18:05 +08:00
|
|
|
/** exeuctes the callback */
|
2010-08-05 17:22:47 +08:00
|
|
|
virtual void execute();
|
|
|
|
//super method
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2010-08-05 17:22:47 +08:00
|
|
|
NSObject * copyWithZone(cocos2d::NSZone *pZone);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SelectorProtocol* m_pSelectorTarget;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
SEL_CallFunc m_pCallFunc;
|
|
|
|
SEL_CallFuncN m_pCallFuncN;
|
|
|
|
SEL_CallFuncND m_pCallFuncND;
|
2010-09-28 16:18:05 +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
|
|
|
|
*/
|
|
|
|
class CCX_DLL CCCallFuncN : public CCCallFunc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCCallFuncN(){}
|
|
|
|
virtual ~CCCallFuncN(){}
|
|
|
|
static CCCallFuncN * actionWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncN selector);
|
2010-09-07 15:13:25 +08:00
|
|
|
virtual bool initWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncN selector);
|
2010-08-05 17:22:47 +08:00
|
|
|
// super method
|
2010-09-07 15:13:25 +08:00
|
|
|
virtual NSObject* copyWithZone(NSZone *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.
|
|
|
|
*/
|
|
|
|
class CCX_DLL CCCallFuncND : public CCCallFuncN
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** creates the action with the callback and the data to pass as an argument */
|
|
|
|
static CCCallFuncND * actionWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncND selector, void* d);
|
|
|
|
/** initializes the action with the callback and the data to pass as an argument */
|
2010-09-04 12:02:52 +08:00
|
|
|
virtual bool initWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncND selector, void* d);
|
2010-08-05 17:22:47 +08:00
|
|
|
// super method
|
|
|
|
virtual NSObject* copyWithZone(NSZone *pZone);
|
|
|
|
virtual void execute();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void *m_pData;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Blocks Support
|
|
|
|
|
|
|
|
#if NS_BLOCKS_AVAILABLE
|
|
|
|
|
|
|
|
/** Executes a callback using a block
|
|
|
|
*/
|
|
|
|
@interface CCCallBlock : CCInstantAction<NSCopying>
|
|
|
|
{
|
|
|
|
void (^block_)();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** creates the action with the specified block, to be used as a callback */
|
|
|
|
+(id) actionWithBlock:(void(^)())block;
|
|
|
|
|
|
|
|
/** initialized the action with the specified block, to be used as a callback */
|
|
|
|
-(id) initWithBlock:(void(^)())block;
|
|
|
|
|
|
|
|
/** executes the callback */
|
|
|
|
-(void) execute;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@class CCNode;
|
|
|
|
|
|
|
|
/** Executes a callback using a block with a single CCNode parameter
|
|
|
|
*/
|
|
|
|
@interface CCCallBlockN : CCInstantAction<NSCopying>
|
|
|
|
{
|
|
|
|
void (^block_)(CCNode *);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** creates the action with the specified block, to be used as a callback */
|
|
|
|
+(id) actionWithBlock:(void(^)(CCNode *node))block;
|
|
|
|
|
|
|
|
/** initialized the action with the specified block, to be used as a callback */
|
|
|
|
-(id) initWithBlock:(void(^)(CCNode *node))block;
|
|
|
|
|
|
|
|
/** executes the callback */
|
|
|
|
-(void) execute;
|
|
|
|
@end
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-09-28 16:18:05 +08:00
|
|
|
#endif //__CCINSTANT_ACTION_H__
|