forked from cocos2d/cocos2d-x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCCAction.h
255 lines (208 loc) · 7.48 KB
/
CCAction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
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__
#include "cocoa/CCObject.h"
#include "cocoa/CCGeometry.h"
#include "platform/CCPlatformMacros.h"
NS_CC_BEGIN
enum {
//! Default tag
kCCActionTagInvalid = -1,
};
/**
* @addtogroup actions
* @{
*/
/**
@brief Base class for CCAction objects.
*/
class CC_DLL CCAction : public CCObject
{
public:
CCAction(void);
virtual ~CCAction(void);
const char* description();
virtual CCObject* copyWithZone(CCZone *pZone);
//! return true if the action has finished
virtual bool isDone(void);
//! called before the action start. It will also set the target.
virtual void startWithTarget(CCNode *pTarget);
/**
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);"
*/
virtual void stop(void);
//! called every frame with it's delta time. DON'T override unless you know what you are doing.
virtual void step(float 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(float time);
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; }
public:
/** Create an action */
static CCAction* create();
protected:
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;
};
/**
@brief
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
Infinite time actions are valid
*/
class CC_DLL CCFiniteTimeAction : public CCAction
{
public:
CCFiniteTimeAction()
: m_fDuration(0)
{}
virtual ~CCFiniteTimeAction(){}
//! get duration in seconds of the action
inline float getDuration(void) { return m_fDuration; }
//! set duration in seconds of the action
inline void setDuration(float duration) { m_fDuration = duration; }
/** returns a reversed action */
virtual CCFiniteTimeAction* reverse(void);
protected:
//! duration in seconds
float m_fDuration;
};
class CCActionInterval;
class CCRepeatForever;
/**
@brief 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 CCIntervalAction
*/
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();
virtual void step(float dt);
virtual bool isDone(void);
virtual CCActionInterval* reverse(void);
void setInnerAction(CCActionInterval *pAction);
inline CCActionInterval* getInnerAction()
{
return m_pInnerAction;
}
public:
/** create the action */
static CCSpeed* create(CCActionInterval* pAction, float fSpeed);
protected:
float m_fSpeed;
CCActionInterval *m_pInnerAction;
};
/**
@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
*/
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 */
bool initWithTarget(CCNode *pFollowedNode, const CCRect& rect = CCRectZero);
virtual CCObject* copyWithZone(CCZone *pZone);
virtual void step(float dt);
virtual bool isDone(void);
virtual void stop(void);
public:
/** 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);
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;
};
// end of actions group
/// @}
NS_CC_END
#endif // __ACTIONS_CCACTION_H__