PageRenderTime 27ms CodeModel.GetById 10ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/libs/cocos2d/CCIntervalAction.h

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