2010-07-20 14:42:56 +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 __ACTIONS_CCACTION_H__
|
|
|
|
#define __ACTIONS_CCACTION_H__
|
|
|
|
|
|
|
|
#include "ccTypes.h"
|
2010-08-05 14:32:04 +08:00
|
|
|
#include "NSObject.h"
|
|
|
|
#include "NSZone.h"
|
2010-08-28 12:02:10 +08:00
|
|
|
#include "CCNode.h"
|
2010-08-04 15:46:12 +08:00
|
|
|
namespace cocos2d {
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
enum {
|
|
|
|
//! Default tag
|
|
|
|
kCCActionTagInvalid = -1,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Base class for CCAction objects.
|
|
|
|
*/
|
2010-08-05 17:22:47 +08:00
|
|
|
class CCX_DLL CCAction : public NSObject
|
2010-07-20 14:42:56 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCAction(void);
|
|
|
|
virtual ~CCAction(void);
|
|
|
|
|
2010-08-06 16:05:19 +08:00
|
|
|
char * description();
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
virtual NSObject* copyWithZone(NSZone *pZone);
|
|
|
|
|
|
|
|
//! return true if the action has finished
|
|
|
|
virtual bool isDone(void);
|
|
|
|
|
|
|
|
//! called before the action start. It will also set the target.
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
//! called after the action has finished. It will set the 'target' to nil.
|
|
|
|
//! IMPORTANT: You should never call "[action stop]" manually. Instead, use: "[target stopAction:action];"
|
2010-08-05 14:32:04 +08:00
|
|
|
virtual void stop(void);
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
//! called every frame with it's delta time. DON'T override unless you know what you are doing.
|
|
|
|
virtual void step(ccTime dt);
|
|
|
|
|
|
|
|
//! called once per frame. time a value between 0 and 1
|
|
|
|
//! For example:
|
|
|
|
//! * 0 means that the action just started
|
|
|
|
//! * 0.5 means that the action is in the middle
|
|
|
|
//! * 1 means that the action is over
|
|
|
|
virtual void update(ccTime time);
|
|
|
|
|
|
|
|
/** The "target". The action will modify the target properties.
|
|
|
|
The target will be set with the 'startWithTarget' method.
|
|
|
|
When the 'stop' method is called, target will be set to nil.
|
|
|
|
The target is 'assigned', it is not 'retained'.
|
|
|
|
*/
|
2010-08-28 12:02:10 +08:00
|
|
|
CCNode* getTarget(void) { return m_pTarget; }
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
/** The original target, since target can be nil.
|
|
|
|
Is the target that were used to run the action. Unless you are doing something complex, like ActionManager, you should NOT call this method.
|
|
|
|
@since v0.8.2
|
|
|
|
*/
|
2010-08-28 12:02:10 +08:00
|
|
|
CCNode* getOriginalTarget(void) { return m_pOriginalTarget; }
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
// The action tag. An identifier of the action
|
2010-08-05 14:32:04 +08:00
|
|
|
int getTag(void) { return m_nTag; }
|
|
|
|
void setTag(int nTag) { m_nTag = nTag; }
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
// Allocates and initializes the action
|
|
|
|
static CCAction* action();
|
|
|
|
|
|
|
|
protected:
|
2010-08-28 12:02:10 +08:00
|
|
|
CCNode *m_pOriginalTarget;
|
|
|
|
CCNode *m_pTarget;
|
2010-08-02 10:58:00 +08:00
|
|
|
int m_nTag;
|
2010-07-20 14:42:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Base class actions that do have a finite time duration.
|
|
|
|
Possible actions:
|
|
|
|
- An action with a duration of 0 seconds
|
|
|
|
- An action with a duration of 35.5 seconds
|
|
|
|
Infitite time actions are valid
|
|
|
|
*/
|
2010-08-05 17:22:47 +08:00
|
|
|
class CCX_DLL CCFiniteTimeAction : public CCAction
|
2010-07-20 14:42:56 +08:00
|
|
|
{
|
|
|
|
public:
|
2010-08-05 17:22:47 +08:00
|
|
|
CCFiniteTimeAction(){}
|
|
|
|
virtual ~CCFiniteTimeAction(){}
|
2010-07-20 14:42:56 +08:00
|
|
|
//! duration in seconds of the action
|
2010-08-05 14:32:04 +08:00
|
|
|
ccTime getDuration(void) { return m_fDuration; }
|
|
|
|
void setDuration(ccTime duration) { m_fDuration = duration; }
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
// returns a reversed action
|
|
|
|
virtual CCFiniteTimeAction* reverse(void);
|
|
|
|
protected:
|
|
|
|
//! duration in seconds
|
|
|
|
ccTime m_fDuration;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CCIntervalAction;
|
|
|
|
/** 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
|
|
|
|
*/
|
2010-08-05 17:22:47 +08:00
|
|
|
class CCX_DLL CCRepeatForever : public CCAction
|
2010-07-20 14:42:56 +08:00
|
|
|
{
|
|
|
|
public:
|
2010-08-05 17:22:47 +08:00
|
|
|
CCRepeatForever(){}
|
2010-08-06 16:05:19 +08:00
|
|
|
virtual ~CCRepeatForever();
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
CCRepeatForever* initWithAction(CCIntervalAction *pAction);
|
|
|
|
virtual NSObject* copyWithZone(NSZone *pZone);
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode* pTarget);
|
2010-07-20 14:42:56 +08:00
|
|
|
virtual void step(ccTime dt);
|
|
|
|
virtual bool isDone(void);
|
|
|
|
virtual CCIntervalAction* reverse(void);
|
|
|
|
|
|
|
|
public:
|
|
|
|
static CCRepeatForever* actionWithAction(CCIntervalAction *pAction);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
CCIntervalAction *m_pOther;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Changes the speed of an action, making it take longer (speed>1)
|
|
|
|
or less (speed<1) time.
|
|
|
|
Useful to simulate 'slow motion' or 'fast forward' effect.
|
|
|
|
@warning This action can't be Sequenceable because it is not an IntervalAction
|
|
|
|
*/
|
2010-08-05 17:22:47 +08:00
|
|
|
class CCX_DLL CCSpeed : public CCAction
|
2010-07-20 14:42:56 +08:00
|
|
|
{
|
|
|
|
public:
|
2010-08-05 17:22:47 +08:00
|
|
|
CCSpeed(){}
|
|
|
|
virtual ~CCSpeed(void);
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
// alter the speed of the inner function in runtime
|
2010-08-05 14:32:04 +08:00
|
|
|
float getSpeed(void) { return m_fSpeed; }
|
|
|
|
void setSpeed(float fSpeed) { m_fSpeed = fSpeed; }
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
// initializes the action
|
2010-08-05 14:32:04 +08:00
|
|
|
CCSpeed* initWithAction(CCIntervalAction *pAction, float fRate);
|
2010-08-25 16:08:10 +08:00
|
|
|
CCSpeed* initWithAction(CCRepeatForever *pAction, float fRate);
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
virtual NSObject* copyWithZone(NSZone *pZone);
|
2010-08-28 12:02:10 +08:00
|
|
|
virtual void startWithTarget(CCNode* pTarget);
|
2010-08-05 14:32:04 +08:00
|
|
|
virtual void stop();
|
2010-07-20 14:42:56 +08:00
|
|
|
virtual void step(ccTime dt);
|
|
|
|
virtual bool isDone(void);
|
|
|
|
virtual CCIntervalAction* reverse(void);
|
|
|
|
|
|
|
|
public:
|
|
|
|
// creates the action
|
|
|
|
static CCSpeed* actionWithAction(CCIntervalAction *pAction, float fRate);
|
2010-08-25 16:08:10 +08:00
|
|
|
static CCSpeed* actionWithAction(CCRepeatForever *pAction, float fRate);
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
float m_fSpeed;
|
|
|
|
CCIntervalAction *m_pOther;
|
2010-08-25 16:08:10 +08:00
|
|
|
CCRepeatForever *m_pRepeat;
|
2010-07-20 14:42:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** CCFollow is an action that "follows" a node.
|
|
|
|
|
|
|
|
Eg:
|
|
|
|
[layer runAction: [CCFollow actionWithTarget:hero]];
|
|
|
|
|
|
|
|
Instead of using CCCamera as a "follower", use this action instead.
|
|
|
|
@since v0.99.2
|
|
|
|
*/
|
|
|
|
class CCNode;
|
|
|
|
class CGPoint;
|
|
|
|
class CGRect;
|
|
|
|
|
2010-08-05 17:22:47 +08:00
|
|
|
class CCX_DLL CCFollow : public CCAction
|
2010-07-20 14:42:56 +08:00
|
|
|
{
|
|
|
|
public:
|
2010-08-05 17:22:47 +08:00
|
|
|
CCFollow(){}
|
|
|
|
virtual ~CCFollow(void);
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
// alter behavior - turn on/off boundary
|
2010-08-05 14:32:04 +08:00
|
|
|
bool isBoundarySet(void) { return m_bBoundarySet; }
|
|
|
|
void setBoudarySet(bool bValue) { m_bBoundarySet = bValue; }
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
// initializes the action
|
|
|
|
CCFollow* initWithTarget(CCNode *pFollowedNode);
|
|
|
|
|
|
|
|
// initializes the action with a set boundary
|
|
|
|
CCFollow* initWithTarget(CCNode *pFollowedNode, CGRect rect);
|
|
|
|
|
|
|
|
virtual NSObject* copyWithZone(NSZone *pZone);
|
|
|
|
virtual void step(ccTime dt);
|
|
|
|
virtual bool isDone(void);
|
2010-08-05 14:32:04 +08:00
|
|
|
virtual void stop(void);
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
// creates the action with no boundary set
|
|
|
|
static CCFollow* actionWithTarget(CCNode *pFollowedNode);
|
|
|
|
|
|
|
|
// creates the action with a set boundary
|
|
|
|
static CCFollow* actionWithTarget(CCNode *pFollowedNode, CGRect rect);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// node to follow
|
|
|
|
CCNode *m_pobFollowedNode;
|
|
|
|
|
|
|
|
// whether camera should be limited to certain area
|
|
|
|
bool m_bBoundarySet;
|
|
|
|
|
|
|
|
// if screensize is bigger than the boundary - update not needed
|
|
|
|
bool m_bBoundaryFullyCovered;
|
|
|
|
|
|
|
|
// fast access to the screen dimensions
|
|
|
|
CGPoint m_obHalfScreenSize;
|
|
|
|
CGPoint m_obFullScreenSize;
|
|
|
|
|
|
|
|
// world boundaries
|
|
|
|
float m_fLeftBoundary;
|
|
|
|
float m_fRightBoundary;
|
|
|
|
float m_fTopBoundary;
|
|
|
|
float m_fBottomBoundary;
|
|
|
|
};
|
2010-08-04 15:46:12 +08:00
|
|
|
}//namespace cocos2d
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
#endif // __ACTIONS_CCACTION_H__
|