2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
2012-06-14 15:13:16 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-04-19 14:35:52 +08:00
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
|
|
|
|
|
|
|
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__
|
|
|
|
|
2012-06-19 13:50:11 +08:00
|
|
|
#include "cocoa/CCObject.h"
|
|
|
|
#include "cocoa/CCGeometry.h"
|
|
|
|
#include "platform/CCPlatformMacros.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2010-07-20 14:42:56 +08:00
|
|
|
enum {
|
2012-04-19 14:35:52 +08:00
|
|
|
//! Default tag
|
|
|
|
kCCActionTagInvalid = -1,
|
|
|
|
};
|
|
|
|
|
2012-06-20 18:07:27 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup actions
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
|
|
|
@brief Base class for CCAction objects.
|
2010-07-20 14:42:56 +08:00
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCAction : public CCObject
|
2010-07-20 14:42:56 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCAction(void);
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual ~CCAction(void);
|
2010-07-20 14:42:56 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
const char* description();
|
2010-07-20 14:42:56 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual CCObject* copyWithZone(CCZone *pZone);
|
2010-07-20 14:42:56 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//! return true if the action has finished
|
|
|
|
virtual bool isDone(void);
|
2010-07-20 14:42:56 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//! called before the action start. It will also set the target.
|
|
|
|
virtual void startWithTarget(CCNode *pTarget);
|
2010-07-20 14:42:56 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/**
|
|
|
|
called after the action has finished. It will set the 'target' to nil.
|
2010-09-29 17:39:45 +08:00
|
|
|
IMPORTANT: You should never call "[action stop]" manually. Instead, use: "target->stopAction(action);"
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
2010-08-05 14:32:04 +08:00
|
|
|
virtual void stop(void);
|
2010-07-20 14:42:56 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//! called every frame with it's delta time. DON'T override unless you know what you are doing.
|
2012-06-08 13:55:28 +08:00
|
|
|
virtual void step(float dt);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
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
|
|
|
|
*/
|
2012-06-08 13:55:28 +08:00
|
|
|
virtual void update(float time);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
inline CCNode* getTarget(void) { return m_pTarget; }
|
|
|
|
/** The action will modify the target properties. */
|
|
|
|
inline void setTarget(CCNode *pTarget) { m_pTarget = pTarget; }
|
|
|
|
|
|
|
|
inline CCNode* getOriginalTarget(void) { return m_pOriginalTarget; }
|
|
|
|
/** Set 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 CCActionManager, you should NOT call this method.
|
|
|
|
The target is 'assigned', it is not 'retained'.
|
|
|
|
@since v0.8.2
|
|
|
|
*/
|
|
|
|
inline void setOriginalTarget(CCNode *pOriginalTarget) { m_pOriginalTarget = pOriginalTarget; }
|
|
|
|
|
|
|
|
inline int getTag(void) { return m_nTag; }
|
|
|
|
inline void setTag(int nTag) { m_nTag = nTag; }
|
2010-07-20 14:42:56 +08:00
|
|
|
|
|
|
|
public:
|
2012-06-14 15:13:16 +08:00
|
|
|
/** Allocates and initializes the action
|
2012-08-10 13:58:34 +08:00
|
|
|
@deprecated: Please use create() instead. This interface will be deprecated sooner or later.
|
2012-06-14 15:13:16 +08:00
|
|
|
*/
|
2012-06-20 11:48:31 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static CCAction* action();
|
2010-07-20 14:42:56 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
/** Create an action */
|
|
|
|
static CCAction* create();
|
2010-07-20 14:42:56 +08:00
|
|
|
protected:
|
2012-04-19 14:35:52 +08:00
|
|
|
CCNode *m_pOriginalTarget;
|
|
|
|
/** The "target".
|
|
|
|
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'.
|
|
|
|
*/
|
|
|
|
CCNode *m_pTarget;
|
|
|
|
/** The action tag. An identifier of the action */
|
|
|
|
int m_nTag;
|
|
|
|
};
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
|
|
|
@brief
|
|
|
|
Base class actions that do have a finite time duration.
|
2010-07-20 14:42:56 +08:00
|
|
|
Possible actions:
|
|
|
|
- An action with a duration of 0 seconds
|
|
|
|
- An action with a duration of 35.5 seconds
|
2010-09-28 18:27:33 +08:00
|
|
|
|
|
|
|
Infinite time actions are valid
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
|
|
|
class CC_DLL CCFiniteTimeAction : public CCAction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCFiniteTimeAction()
|
|
|
|
: m_fDuration(0)
|
|
|
|
{}
|
|
|
|
virtual ~CCFiniteTimeAction(){}
|
|
|
|
//! get duration in seconds of the action
|
2012-06-08 13:55:28 +08:00
|
|
|
inline float getDuration(void) { return m_fDuration; }
|
2012-04-19 14:35:52 +08:00
|
|
|
//! set duration in seconds of the action
|
2012-06-08 13:55:28 +08:00
|
|
|
inline void setDuration(float duration) { m_fDuration = duration; }
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** returns a reversed action */
|
|
|
|
virtual CCFiniteTimeAction* reverse(void);
|
|
|
|
protected:
|
|
|
|
//! duration in seconds
|
2012-06-08 13:55:28 +08:00
|
|
|
float m_fDuration;
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class CCActionInterval;
|
|
|
|
class CCRepeatForever;
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
|
|
|
@brief Changes the speed of an action, making it take longer (speed>1)
|
2010-07-20 14:42:56 +08:00
|
|
|
or less (speed<1) time.
|
|
|
|
Useful to simulate 'slow motion' or 'fast forward' effect.
|
2011-07-01 15:08:23 +08:00
|
|
|
@warning This action can't be Sequenceable because it is not an CCIntervalAction
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
|
|
|
class CC_DLL CCSpeed : public CCAction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCSpeed()
|
|
|
|
: m_fSpeed(0.0)
|
|
|
|
, m_pInnerAction(NULL)
|
|
|
|
{}
|
|
|
|
virtual ~CCSpeed(void);
|
|
|
|
|
|
|
|
inline float getSpeed(void) { return m_fSpeed; }
|
|
|
|
/** alter the speed of the inner function in runtime */
|
|
|
|
inline void setSpeed(float fSpeed) { m_fSpeed = fSpeed; }
|
|
|
|
|
|
|
|
/** initializes the action */
|
|
|
|
bool initWithAction(CCActionInterval *pAction, float fSpeed);
|
|
|
|
|
|
|
|
virtual CCObject* copyWithZone(CCZone *pZone);
|
|
|
|
virtual void startWithTarget(CCNode* pTarget);
|
|
|
|
virtual void stop();
|
2012-06-08 13:55:28 +08:00
|
|
|
virtual void step(float dt);
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual bool isDone(void);
|
|
|
|
virtual CCActionInterval* reverse(void);
|
|
|
|
|
|
|
|
void setInnerAction(CCActionInterval *pAction);
|
|
|
|
|
|
|
|
inline CCActionInterval* getInnerAction()
|
|
|
|
{
|
|
|
|
return m_pInnerAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2012-06-14 15:13:16 +08:00
|
|
|
/** creates the action
|
2012-08-10 13:58:34 +08:00
|
|
|
@deprecated: Please use create(CCActionInterval* float) instead. This interface will be deprecated sooner or later.
|
2012-06-14 15:13:16 +08:00
|
|
|
*/
|
2012-06-20 11:48:31 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static CCSpeed* actionWithAction(CCActionInterval *pAction, float fSpeed);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
/** create the action */
|
|
|
|
static CCSpeed* create(CCActionInterval* pAction, float fSpeed);
|
2012-04-19 14:35:52 +08:00
|
|
|
protected:
|
|
|
|
float m_fSpeed;
|
|
|
|
CCActionInterval *m_pInnerAction;
|
|
|
|
};
|
|
|
|
|
2010-09-28 18:27:33 +08:00
|
|
|
/**
|
|
|
|
@brief 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
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
|
|
|
class CC_DLL CCFollow : public CCAction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCFollow()
|
|
|
|
: m_pobFollowedNode(NULL)
|
|
|
|
, m_bBoundarySet(false)
|
|
|
|
, m_bBoundaryFullyCovered(false)
|
|
|
|
, m_fLeftBoundary(0.0)
|
|
|
|
, m_fRightBoundary(0.0)
|
|
|
|
, m_fTopBoundary(0.0)
|
|
|
|
, m_fBottomBoundary(0.0)
|
|
|
|
{}
|
|
|
|
virtual ~CCFollow(void);
|
|
|
|
|
|
|
|
inline bool isBoundarySet(void) { return m_bBoundarySet; }
|
|
|
|
/** alter behavior - turn on/off boundary */
|
|
|
|
inline void setBoudarySet(bool bValue) { m_bBoundarySet = bValue; }
|
|
|
|
|
|
|
|
/** initializes the action with a set boundary */
|
2012-06-14 15:13:16 +08:00
|
|
|
bool initWithTarget(CCNode *pFollowedNode, const CCRect& rect = CCRectZero);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
virtual CCObject* copyWithZone(CCZone *pZone);
|
2012-06-08 13:55:28 +08:00
|
|
|
virtual void step(float dt);
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual bool isDone(void);
|
|
|
|
virtual void stop(void);
|
|
|
|
|
|
|
|
public:
|
2012-06-14 15:13:16 +08:00
|
|
|
/** creates the action with a set boundary,
|
|
|
|
It will work with no boundary if @param rect is equal to CCRectZero.
|
2012-09-16 06:12:28 +08:00
|
|
|
@deprecated: Please use create(CCNode*, const CCRect&) instead. This interface will be deprecated sooner or later.
|
2012-06-14 15:13:16 +08:00
|
|
|
*/
|
2012-06-20 11:48:31 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static CCFollow* actionWithTarget(CCNode *pFollowedNode, const CCRect& rect = CCRectZero);
|
2012-06-14 15:13:16 +08:00
|
|
|
/** creates the action with a set boundary,
|
|
|
|
It will work with no boundary if @param rect is equal to CCRectZero.
|
|
|
|
*/
|
|
|
|
static CCFollow* create(CCNode *pFollowedNode, const CCRect& rect = CCRectZero);
|
2012-04-19 14:35:52 +08:00
|
|
|
protected:
|
|
|
|
// node to follow
|
|
|
|
CCNode *m_pobFollowedNode;
|
|
|
|
|
|
|
|
// whether camera should be limited to certain area
|
|
|
|
bool m_bBoundarySet;
|
|
|
|
|
|
|
|
// if screen size is bigger than the boundary - update not needed
|
|
|
|
bool m_bBoundaryFullyCovered;
|
|
|
|
|
|
|
|
// fast access to the screen dimensions
|
|
|
|
CCPoint m_obHalfScreenSize;
|
|
|
|
CCPoint m_obFullScreenSize;
|
|
|
|
|
|
|
|
// world boundaries
|
|
|
|
float m_fLeftBoundary;
|
|
|
|
float m_fRightBoundary;
|
|
|
|
float m_fTopBoundary;
|
|
|
|
float m_fBottomBoundary;
|
|
|
|
};
|
|
|
|
|
2012-06-20 18:07:27 +08:00
|
|
|
// end of actions group
|
|
|
|
/// @}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif // __ACTIONS_CCACTION_H__
|