summary refs log tree commit diff stats
path: root/libs/cocos2d/CCActionInterval.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/cocos2d/CCActionInterval.h')
-rwxr-xr-xlibs/cocos2d/CCActionInterval.h421
1 files changed, 421 insertions, 0 deletions
diff --git a/libs/cocos2d/CCActionInterval.h b/libs/cocos2d/CCActionInterval.h new file mode 100755 index 0000000..c667963 --- /dev/null +++ b/libs/cocos2d/CCActionInterval.h
@@ -0,0 +1,421 @@
1/*
2 * cocos2d for iPhone: http://www.cocos2d-iphone.org
3 *
4 * Copyright (c) 2008-2011 Ricardo Quesada
5 * Copyright (c) 2011 Zynga Inc.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 *
25 */
26
27
28#import "CCNode.h"
29#import "CCAction.h"
30#import "CCProtocols.h"
31
32#include <sys/time.h>
33
34/** An interval action is an action that takes place within a certain period of time.
35It has an start time, and a finish time. The finish time is the parameter
36duration plus the start time.
37
38These CCActionInterval actions have some interesting properties, like:
39 - They can run normally (default)
40 - They can run reversed with the reverse method
41 - They can run with the time altered with the Accelerate, AccelDeccel and Speed actions.
42
43For example, you can simulate a Ping Pong effect running the action normally and
44then running it again in Reverse mode.
45
46Example:
47
48 CCAction * pingPongAction = [CCSequence actions: action, [action reverse], nil];
49*/
50@interface CCActionInterval: CCFiniteTimeAction <NSCopying>
51{
52 ccTime elapsed_;
53 BOOL firstTick_;
54}
55
56/** how many seconds had elapsed since the actions started to run. */
57@property (nonatomic,readonly) ccTime elapsed;
58
59/** creates the action */
60+(id) actionWithDuration: (ccTime) d;
61/** initializes the action */
62-(id) initWithDuration: (ccTime) d;
63/** returns YES if the action has finished */
64-(BOOL) isDone;
65/** returns a reversed action */
66- (CCActionInterval*) reverse;
67@end
68
69/** Runs actions sequentially, one after another
70 */
71@interface CCSequence : CCActionInterval <NSCopying>
72{
73 CCFiniteTimeAction *actions_[2];
74 ccTime split_;
75 int last_;
76}
77/** helper contructor to create an array of sequenceable actions */
78+(id) actions: (CCFiniteTimeAction*) action1, ... NS_REQUIRES_NIL_TERMINATION;
79/** helper contructor to create an array of sequenceable actions given an array */
80+(id) actionsWithArray: (NSArray*) actions;
81/** creates the action */
82+(id) actionOne:(CCFiniteTimeAction*)actionOne two:(CCFiniteTimeAction*)actionTwo;
83/** initializes the action */
84-(id) initOne:(CCFiniteTimeAction*)actionOne two:(CCFiniteTimeAction*)actionTwo;
85@end
86
87
88/** Repeats an action a number of times.
89 * To repeat an action forever use the CCRepeatForever action.
90 */
91@interface CCRepeat : CCActionInterval <NSCopying>
92{
93 NSUInteger times_;
94 NSUInteger total_;
95 CCFiniteTimeAction *innerAction_;
96}
97
98/** Inner action */
99@property (nonatomic,readwrite,retain) CCFiniteTimeAction *innerAction;
100
101/** creates a CCRepeat action. Times is an unsigned integer between 1 and MAX_UINT */
102+(id) actionWithAction:(CCFiniteTimeAction*)action times: (NSUInteger)times;
103/** initializes a CCRepeat action. Times is an unsigned integer between 1 and MAX_UINT */
104-(id) initWithAction:(CCFiniteTimeAction*)action times: (NSUInteger)times;
105@end
106
107/** Spawn a new action immediately
108 */
109@interface CCSpawn : CCActionInterval <NSCopying>
110{
111 CCFiniteTimeAction *one_;
112 CCFiniteTimeAction *two_;
113}
114/** helper constructor to create an array of spawned actions */
115+(id) actions: (CCFiniteTimeAction*) action1, ... NS_REQUIRES_NIL_TERMINATION;
116/** helper contructor to create an array of spawned actions given an array */
117+(id) actionsWithArray: (NSArray*) actions;
118/** creates the Spawn action */
119+(id) actionOne: (CCFiniteTimeAction*) one two:(CCFiniteTimeAction*) two;
120/** initializes the Spawn action with the 2 actions to spawn */
121-(id) initOne: (CCFiniteTimeAction*) one two:(CCFiniteTimeAction*) two;
122@end
123
124/** Rotates a CCNode object to a certain angle by modifying it's
125 rotation attribute.
126 The direction will be decided by the shortest angle.
127*/
128@interface CCRotateTo : CCActionInterval <NSCopying>
129{
130 float dstAngle_;
131 float startAngle_;
132 float diffAngle_;
133}
134/** creates the action */
135+(id) actionWithDuration:(ccTime)duration angle:(float)angle;
136/** initializes the action */
137-(id) initWithDuration:(ccTime)duration angle:(float)angle;
138@end
139
140/** Rotates a CCNode object clockwise a number of degrees by modiying it's rotation attribute.
141*/
142@interface CCRotateBy : CCActionInterval <NSCopying>
143{
144 float angle_;
145 float startAngle_;
146}
147/** creates the action */
148+(id) actionWithDuration:(ccTime)duration angle:(float)deltaAngle;
149/** initializes the action */
150-(id) initWithDuration:(ccTime)duration angle:(float)deltaAngle;
151@end
152
153/** Moves a CCNode object to the position x,y. x and y are absolute coordinates by modifying it's position attribute.
154*/
155@interface CCMoveTo : CCActionInterval <NSCopying>
156{
157 CGPoint endPosition_;
158 CGPoint startPosition_;
159 CGPoint delta_;
160}
161/** creates the action */
162+(id) actionWithDuration:(ccTime)duration position:(CGPoint)position;
163/** initializes the action */
164-(id) initWithDuration:(ccTime)duration position:(CGPoint)position;
165@end
166
167/** Moves a CCNode object x,y pixels by modifying it's position attribute.
168 x and y are relative to the position of the object.
169 Duration is is seconds.
170*/
171@interface CCMoveBy : CCMoveTo <NSCopying>
172{
173}
174/** creates the action */
175+(id) actionWithDuration: (ccTime)duration position:(CGPoint)deltaPosition;
176/** initializes the action */
177-(id) initWithDuration: (ccTime)duration position:(CGPoint)deltaPosition;
178@end
179
180/** Skews a CCNode object to given angles by modifying it's skewX and skewY attributes
181 @since v1.0
182 */
183@interface CCSkewTo : CCActionInterval <NSCopying>
184{
185 float skewX_;
186 float skewY_;
187 float startSkewX_;
188 float startSkewY_;
189 float endSkewX_;
190 float endSkewY_;
191 float deltaX_;
192 float deltaY_;
193}
194/** creates the action */
195+(id) actionWithDuration:(ccTime)t skewX:(float)sx skewY:(float)sy;
196/** initializes the action */
197-(id) initWithDuration:(ccTime)t skewX:(float)sx skewY:(float)sy;
198@end
199
200/** Skews a CCNode object by skewX and skewY degrees
201 @since v1.0
202 */
203@interface CCSkewBy : CCSkewTo <NSCopying>
204{
205}
206@end
207
208/** Moves a CCNode object simulating a parabolic jump movement by modifying it's position attribute.
209*/
210 @interface CCJumpBy : CCActionInterval <NSCopying>
211{
212 CGPoint startPosition_;
213 CGPoint delta_;
214 ccTime height_;
215 NSUInteger jumps_;
216}
217/** creates the action */
218+(id) actionWithDuration: (ccTime)duration position:(CGPoint)position height:(ccTime)height jumps:(NSUInteger)jumps;
219/** initializes the action */
220-(id) initWithDuration: (ccTime)duration position:(CGPoint)position height:(ccTime)height jumps:(NSUInteger)jumps;
221@end
222
223/** Moves a CCNode object to a parabolic position simulating a jump movement by modifying it's position attribute.
224*/
225 @interface CCJumpTo : CCJumpBy <NSCopying>
226{
227}
228@end
229
230/** bezier configuration structure
231 */
232typedef struct _ccBezierConfig {
233 //! end position of the bezier
234 CGPoint endPosition;
235 //! Bezier control point 1
236 CGPoint controlPoint_1;
237 //! Bezier control point 2
238 CGPoint controlPoint_2;
239} ccBezierConfig;
240
241/** An action that moves the target with a cubic Bezier curve by a certain distance.
242 */
243@interface CCBezierBy : CCActionInterval <NSCopying>
244{
245 ccBezierConfig config_;
246 CGPoint startPosition_;
247}
248
249/** creates the action with a duration and a bezier configuration */
250+(id) actionWithDuration: (ccTime) t bezier:(ccBezierConfig) c;
251
252/** initializes the action with a duration and a bezier configuration */
253-(id) initWithDuration: (ccTime) t bezier:(ccBezierConfig) c;
254@end
255
256/** An action that moves the target with a cubic Bezier curve to a destination point.
257 @since v0.8.2
258 */
259@interface CCBezierTo : CCBezierBy
260{
261}
262@end
263
264/** Scales a CCNode object to a zoom factor by modifying it's scale attribute.
265 @warning This action doesn't support "reverse"
266 */
267@interface CCScaleTo : CCActionInterval <NSCopying>
268{
269 float scaleX_;
270 float scaleY_;
271 float startScaleX_;
272 float startScaleY_;
273 float endScaleX_;
274 float endScaleY_;
275 float deltaX_;
276 float deltaY_;
277}
278/** creates the action with the same scale factor for X and Y */
279+(id) actionWithDuration: (ccTime)duration scale:(float) s;
280/** initializes the action with the same scale factor for X and Y */
281-(id) initWithDuration: (ccTime)duration scale:(float) s;
282/** creates the action with and X factor and a Y factor */
283+(id) actionWithDuration: (ccTime)duration scaleX:(float) sx scaleY:(float)sy;
284/** initializes the action with and X factor and a Y factor */
285-(id) initWithDuration: (ccTime)duration scaleX:(float) sx scaleY:(float)sy;
286@end
287
288/** Scales a CCNode object a zoom factor by modifying it's scale attribute.
289*/
290@interface CCScaleBy : CCScaleTo <NSCopying>
291{
292}
293@end
294
295/** Blinks a CCNode object by modifying it's visible attribute
296*/
297@interface CCBlink : CCActionInterval <NSCopying>
298{
299 NSUInteger times_;
300}
301/** creates the action */
302+(id) actionWithDuration: (ccTime)duration blinks:(NSUInteger)blinks;
303/** initilizes the action */
304-(id) initWithDuration: (ccTime)duration blinks:(NSUInteger)blinks;
305@end
306
307/** Fades In an object that implements the CCRGBAProtocol protocol. It modifies the opacity from 0 to 255.
308 The "reverse" of this action is FadeOut
309 */
310@interface CCFadeIn : CCActionInterval <NSCopying>
311{
312}
313@end
314
315/** Fades Out an object that implements the CCRGBAProtocol protocol. It modifies the opacity from 255 to 0.
316 The "reverse" of this action is FadeIn
317*/
318@interface CCFadeOut : CCActionInterval <NSCopying>
319{
320}
321@end
322
323/** Fades an object that implements the CCRGBAProtocol protocol. It modifies the opacity from the current value to a custom one.
324 @warning This action doesn't support "reverse"
325 */
326@interface CCFadeTo : CCActionInterval <NSCopying>
327{
328 GLubyte toOpacity_;
329 GLubyte fromOpacity_;
330}
331/** creates an action with duration and opactiy */
332+(id) actionWithDuration:(ccTime)duration opacity:(GLubyte)opactiy;
333/** initializes the action with duration and opacity */
334-(id) initWithDuration:(ccTime)duration opacity:(GLubyte)opacity;
335@end
336
337/** Tints a CCNode that implements the CCNodeRGB protocol from current tint to a custom one.
338 @warning This action doesn't support "reverse"
339 @since v0.7.2
340*/
341@interface CCTintTo : CCActionInterval <NSCopying>
342{
343 ccColor3B to_;
344 ccColor3B from_;
345}
346/** creates an action with duration and color */
347+(id) actionWithDuration:(ccTime)duration red:(GLubyte)red green:(GLubyte)green blue:(GLubyte)blue;
348/** initializes the action with duration and color */
349-(id) initWithDuration:(ccTime)duration red:(GLubyte)red green:(GLubyte)green blue:(GLubyte)blue;
350@end
351
352/** Tints a CCNode that implements the CCNodeRGB protocol from current tint to a custom one.
353 @since v0.7.2
354 */
355@interface CCTintBy : CCActionInterval <NSCopying>
356{
357 GLshort deltaR_, deltaG_, deltaB_;
358 GLshort fromR_, fromG_, fromB_;
359}
360/** creates an action with duration and color */
361+(id) actionWithDuration:(ccTime)duration red:(GLshort)deltaRed green:(GLshort)deltaGreen blue:(GLshort)deltaBlue;
362/** initializes the action with duration and color */
363-(id) initWithDuration:(ccTime)duration red:(GLshort)deltaRed green:(GLshort)deltaGreen blue:(GLshort)deltaBlue;
364@end
365
366/** Delays the action a certain amount of seconds
367*/
368@interface CCDelayTime : CCActionInterval <NSCopying>
369{
370}
371@end
372
373/** Executes an action in reverse order, from time=duration to time=0
374
375 @warning Use this action carefully. This action is not
376 sequenceable. Use it as the default "reversed" method
377 of your own actions, but using it outside the "reversed"
378 scope is not recommended.
379*/
380@interface CCReverseTime : CCActionInterval <NSCopying>
381{
382 CCFiniteTimeAction * other_;
383}
384/** creates the action */
385+(id) actionWithAction: (CCFiniteTimeAction*) action;
386/** initializes the action */
387-(id) initWithAction: (CCFiniteTimeAction*) action;
388@end
389
390
391@class CCAnimation;
392@class CCTexture2D;
393/** Animates a sprite given the name of an Animation */
394@interface CCAnimate : CCActionInterval <NSCopying>
395{
396 CCAnimation *animation_;
397 id origFrame_;
398 BOOL restoreOriginalFrame_;
399}
400/** animation used for the animage */
401@property (readwrite,nonatomic,retain) CCAnimation * animation;
402
403/** creates the action with an Animation and will restore the original frame when the animation is over */
404+(id) actionWithAnimation:(CCAnimation*) a;
405/** initializes the action with an Animation and will restore the original frame when the animtion is over */
406-(id) initWithAnimation:(CCAnimation*) a;
407/** creates the action with an Animation */
408+(id) actionWithAnimation:(CCAnimation*) a restoreOriginalFrame:(BOOL)b;
409/** initializes the action with an Animation */
410-(id) initWithAnimation:(CCAnimation*) a restoreOriginalFrame:(BOOL)b;
411/** creates an action with a duration, animation and depending of the restoreOriginalFrame, it will restore the original frame or not.
412 The 'delay' parameter of the animation will be overrided by the duration parameter.
413 @since v0.99.0
414 */
415+(id) actionWithDuration:(ccTime)duration animation:(CCAnimation*)animation restoreOriginalFrame:(BOOL)b;
416/** initializes an action with a duration, animation and depending of the restoreOriginalFrame, it will restore the original frame or not.
417 The 'delay' parameter of the animation will be overrided by the duration parameter.
418 @since v0.99.0
419 */
420-(id) initWithDuration:(ccTime)duration animation:(CCAnimation*)animation restoreOriginalFrame:(BOOL)b;
421@end