/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. #import "CCNode.h"
  26. #import "CCAction.h"
  27. #import "CCProtocols.h"
  28. #include <sys/time.h>
  29. /** An interval action is an action that takes place within a certain period of time.
  30. It has an start time, and a finish time. The finish time is the parameter
  31. duration plus the start time.
  32. These CCIntervalAction actions have some interesting properties, like:
  33. - They can run normally (default)
  34. - They can run reversed with the reverse method
  35. - They can run with the time altered with the Accelerate, AccelDeccel and Speed actions.
  36. For example, you can simulate a Ping Pong effect running the action normally and
  37. then running it again in Reverse mode.
  38. Example:
  39. CCAction * pingPongAction = [CCSequence actions: action, [action reverse], nil];
  40. */
  41. @interface CCIntervalAction: CCFiniteTimeAction <NSCopying>
  42. {
  43. ccTime elapsed;
  44. BOOL firstTick;
  45. }
  46. /** how many seconds had elapsed since the actions started to run. */
  47. @property (nonatomic,readonly) ccTime elapsed;
  48. /** creates the action */
  49. +(id) actionWithDuration: (ccTime) d;
  50. /** initializes the action */
  51. -(id) initWithDuration: (ccTime) d;
  52. /** returns YES if the action has finished */
  53. -(BOOL) isDone;
  54. /** returns a reversed action */
  55. - (CCIntervalAction*) reverse;
  56. @end
  57. /** Runs actions sequentially, one after another
  58. */
  59. @interface CCSequence : CCIntervalAction <NSCopying>
  60. {
  61. CCFiniteTimeAction *actions[2];
  62. ccTime split;
  63. int last;
  64. }
  65. /** helper contructor to create an array of sequenceable actions */
  66. +(id) actions: (CCFiniteTimeAction*) action1, ... NS_REQUIRES_NIL_TERMINATION;
  67. /** creates the action */
  68. +(id) actionOne:(CCFiniteTimeAction*)actionOne two:(CCFiniteTimeAction*)actionTwo;
  69. /** initializes the action */
  70. -(id) initOne:(CCFiniteTimeAction*)actionOne two:(CCFiniteTimeAction*)actionTwo;
  71. @end
  72. /** Repeats an action a number of times.
  73. * To repeat an action forever use the CCRepeatForever action.
  74. */
  75. @interface CCRepeat : CCIntervalAction <NSCopying>
  76. {
  77. unsigned int times_;
  78. unsigned int total_;
  79. CCFiniteTimeAction *other_;
  80. }
  81. /** creates a CCRepeat action. Times is an unsigned integer between 1 and pow(2,30) */
  82. +(id) actionWithAction:(CCFiniteTimeAction*)action times: (unsigned int)times;
  83. /** initializes a CCRepeat action. Times is an unsigned integer between 1 and pow(2,30) */
  84. -(id) initWithAction:(CCFiniteTimeAction*)action times: (unsigned int)times;
  85. @end
  86. /** Spawn a new action immediately
  87. */
  88. @interface CCSpawn : CCIntervalAction <NSCopying>
  89. {
  90. CCFiniteTimeAction *one;
  91. CCFiniteTimeAction *two;
  92. }
  93. /** helper constructor to create an array of spawned actions */
  94. +(id) actions: (CCFiniteTimeAction*) action1, ... NS_REQUIRES_NIL_TERMINATION;
  95. /** creates the Spawn action */
  96. +(id) actionOne: (CCFiniteTimeAction*) one two:(CCFiniteTimeAction*) two;
  97. /** initializes the Spawn action with the 2 actions to spawn */
  98. -(id) initOne: (CCFiniteTimeAction*) one two:(CCFiniteTimeAction*) two;
  99. @end
  100. /** Rotates a CCNode object to a certain angle by modifying it's
  101. rotation attribute.
  102. The direction will be decided by the shortest angle.
  103. */
  104. @interface CCRotateTo : CCIntervalAction <NSCopying>
  105. {
  106. float dstAngle;
  107. float startAngle;
  108. float diffAngle;
  109. }
  110. /** creates the action */
  111. +(id) actionWithDuration:(ccTime)duration angle:(float)angle;
  112. /** initializes the action */
  113. -(id) initWithDuration:(ccTime)duration angle:(float)angle;
  114. @end
  115. /** Rotates a CCNode object clockwise a number of degrees by modiying it's rotation attribute.
  116. */
  117. @interface CCRotateBy : CCIntervalAction <NSCopying>
  118. {
  119. float angle;
  120. float startAngle;
  121. }
  122. /** creates the action */
  123. +(id) actionWithDuration:(ccTime)duration angle:(float)deltaAngle;
  124. /** initializes the action */
  125. -(id) initWithDuration:(ccTime)duration angle:(float)deltaAngle;
  126. @end
  127. /** Moves a CCNode object to the position x,y. x and y are absolute coordinates by modifying it's position attribute.
  128. */
  129. @interface CCMoveTo : CCIntervalAction <NSCopying>
  130. {
  131. CGPoint endPosition;
  132. CGPoint startPosition;
  133. CGPoint delta;
  134. }
  135. /** creates the action */
  136. +(id) actionWithDuration:(ccTime)duration position:(CGPoint)position;
  137. /** initializes the action */
  138. -(id) initWithDuration:(ccTime)duration position:(CGPoint)position;
  139. @end
  140. /** Moves a CCNode object x,y pixels by modifying it's position attribute.
  141. x and y are relative to the position of the object.
  142. Duration is is seconds.
  143. */
  144. @interface CCMoveBy : CCMoveTo <NSCopying>
  145. {
  146. }
  147. /** creates the action */
  148. +(id) actionWithDuration: (ccTime)duration position:(CGPoint)deltaPosition;
  149. /** initializes the action */
  150. -(id) initWithDuration: (ccTime)duration position:(CGPoint)deltaPosition;
  151. @end
  152. /** Moves a CCNode object simulating a parabolic jump movement by modifying it's position attribute.
  153. */
  154. @interface CCJumpBy : CCIntervalAction <NSCopying>
  155. {
  156. CGPoint startPosition;
  157. CGPoint delta;
  158. ccTime height;
  159. int jumps;
  160. }
  161. /** creates the action */
  162. +(id) actionWithDuration: (ccTime)duration position:(CGPoint)position height:(ccTime)height jumps:(int)jumps;
  163. /** initializes the action */
  164. -(id) initWithDuration: (ccTime)duration position:(CGPoint)position height:(ccTime)height jumps:(int)jumps;
  165. @end
  166. /** Moves a CCNode object to a parabolic position simulating a jump movement by modifying it's position attribute.
  167. */
  168. @interface CCJumpTo : CCJumpBy <NSCopying>
  169. {
  170. }
  171. @end
  172. /** bezier configuration structure
  173. */
  174. typedef struct _ccBezierConfig {
  175. //! end position of the bezier
  176. CGPoint endPosition;
  177. //! Bezier control point 1
  178. CGPoint controlPoint_1;
  179. //! Bezier control point 2
  180. CGPoint controlPoint_2;
  181. } ccBezierConfig;
  182. /** An action that moves the target with a cubic Bezier curve by a certain distance.
  183. */
  184. @interface CCBezierBy : CCIntervalAction <NSCopying>
  185. {
  186. ccBezierConfig config;
  187. CGPoint startPosition;
  188. }
  189. /** creates the action with a duration and a bezier configuration */
  190. +(id) actionWithDuration: (ccTime) t bezier:(ccBezierConfig) c;
  191. /** initializes the action with a duration and a bezier configuration */
  192. -(id) initWithDuration: (ccTime) t bezier:(ccBezierConfig) c;
  193. @end
  194. /** An action that moves the target with a cubic Bezier curve to a destination point.
  195. @since v0.8.2
  196. */
  197. @interface CCBezierTo : CCBezierBy
  198. {
  199. }
  200. @end
  201. /** Scales a CCNode object to a zoom factor by modifying it's scale attribute.
  202. @warning This action doesn't support "reverse"
  203. */
  204. @interface CCScaleTo : CCIntervalAction <NSCopying>
  205. {
  206. float scaleX;
  207. float scaleY;
  208. float startScaleX;
  209. float startScaleY;
  210. float endScaleX;
  211. float endScaleY;
  212. float deltaX;
  213. float deltaY;
  214. }
  215. /** creates the action with the same scale factor for X and Y */
  216. +(id) actionWithDuration: (ccTime)duration scale:(float) s;
  217. /** initializes the action with the same scale factor for X and Y */
  218. -(id) initWithDuration: (ccTime)duration scale:(float) s;
  219. /** creates the action with and X factor and a Y factor */
  220. +(id) actionWithDuration: (ccTime)duration scaleX:(float) sx scaleY:(float)sy;
  221. /** initializes the action with and X factor and a Y factor */
  222. -(id) initWithDuration: (ccTime)duration scaleX:(float) sx scaleY:(float)sy;
  223. @end
  224. /** Scales a CCNode object a zoom factor by modifying it's scale attribute.
  225. */
  226. @interface CCScaleBy : CCScaleTo <NSCopying>
  227. {
  228. }
  229. @end
  230. /** Blinks a CCNode object by modifying it's visible attribute
  231. */
  232. @interface CCBlink : CCIntervalAction <NSCopying>
  233. {
  234. int times;
  235. }
  236. /** creates the action */
  237. +(id) actionWithDuration: (ccTime)duration blinks:(unsigned int)blinks;
  238. /** initilizes the action */
  239. -(id) initWithDuration: (ccTime)duration blinks:(unsigned int)blinks;
  240. @end
  241. /** Fades In an object that implements the CCRGBAProtocol protocol. It modifies the opacity from 0 to 255.
  242. The "reverse" of this action is FadeOut
  243. */
  244. @interface CCFadeIn : CCIntervalAction <NSCopying>
  245. {
  246. }
  247. @end
  248. /** Fades Out an object that implements the CCRGBAProtocol protocol. It modifies the opacity from 255 to 0.
  249. The "reverse" of this action is FadeIn
  250. */
  251. @interface CCFadeOut : CCIntervalAction <NSCopying>
  252. {
  253. }
  254. @end
  255. /** Fades an object that implements the CCRGBAProtocol protocol. It modifies the opacity from the current value to a custom one.
  256. @warning This action doesn't support "reverse"
  257. */
  258. @interface CCFadeTo : CCIntervalAction <NSCopying>
  259. {
  260. GLubyte toOpacity;
  261. GLubyte fromOpacity;
  262. }
  263. /** creates an action with duration and opactiy */
  264. +(id) actionWithDuration:(ccTime)duration opacity:(GLubyte)opactiy;
  265. /** initializes the action with duration and opacity */
  266. -(id) initWithDuration:(ccTime)duration opacity:(GLubyte)opacity;
  267. @end
  268. /** Tints a CCNode that implements the CCNodeRGB protocol from current tint to a custom one.
  269. @warning This action doesn't support "reverse"
  270. @since v0.7.2
  271. */
  272. @interface CCTintTo : CCIntervalAction <NSCopying>
  273. {
  274. ccColor3B to;
  275. ccColor3B from;
  276. }
  277. /** creates an action with duration and color */
  278. +(id) actionWithDuration:(ccTime)duration red:(GLubyte)red green:(GLubyte)green blue:(GLubyte)blue;
  279. /** initializes the action with duration and color */
  280. -(id) initWithDuration:(ccTime)duration red:(GLubyte)red green:(GLubyte)green blue:(GLubyte)blue;
  281. @end
  282. /** Tints a CCNode that implements the CCNodeRGB protocol from current tint to a custom one.
  283. @since v0.7.2
  284. */
  285. @interface CCTintBy : CCIntervalAction <NSCopying>
  286. {
  287. GLshort deltaR, deltaG, deltaB;
  288. GLshort fromR, fromG, fromB;
  289. }
  290. /** creates an action with duration and color */
  291. +(id) actionWithDuration:(ccTime)duration red:(GLshort)deltaRed green:(GLshort)deltaGreen blue:(GLshort)deltaBlue;
  292. /** initializes the action with duration and color */
  293. -(id) initWithDuration:(ccTime)duration red:(GLshort)deltaRed green:(GLshort)deltaGreen blue:(GLshort)deltaBlue;
  294. @end
  295. /** Delays the action a certain amount of seconds
  296. */
  297. @interface CCDelayTime : CCIntervalAction <NSCopying>
  298. {
  299. }
  300. @end
  301. /** Executes an action in reverse order, from time=duration to time=0
  302. @warning Use this action carefully. This action is not
  303. sequenceable. Use it as the default "reversed" method
  304. of your own actions, but using it outside the "reversed"
  305. scope is not recommended.
  306. */
  307. @interface CCReverseTime : CCIntervalAction <NSCopying>
  308. {
  309. CCFiniteTimeAction * other;
  310. }
  311. /** creates the action */
  312. +(id) actionWithAction: (CCFiniteTimeAction*) action;
  313. /** initializes the action */
  314. -(id) initWithAction: (CCFiniteTimeAction*) action;
  315. @end
  316. @class CCAnimation;
  317. @class CCTexture2D;
  318. /** Animates a sprite given the name of an Animation */
  319. @interface CCAnimate : CCIntervalAction <NSCopying>
  320. {
  321. CCAnimation *animation_;
  322. id origFrame;
  323. BOOL restoreOriginalFrame;
  324. }
  325. /** animation used for the animage */
  326. @property (readwrite,nonatomic,retain) CCAnimation * animation;
  327. /** creates the action with an Animation and will restore the original frame when the animation is over */
  328. +(id) actionWithAnimation:(CCAnimation*) a;
  329. /** initializes the action with an Animation and will restore the original frame when the animtion is over */
  330. -(id) initWithAnimation:(CCAnimation*) a;
  331. /** creates the action with an Animation */
  332. +(id) actionWithAnimation:(CCAnimation*) a restoreOriginalFrame:(BOOL)b;
  333. /** initializes the action with an Animation */
  334. -(id) initWithAnimation:(CCAnimation*) a restoreOriginalFrame:(BOOL)b;
  335. /** creates an action with a duration, animation and depending of the restoreOriginalFrame, it will restore the original frame or not.
  336. The 'delay' parameter of the animation will be overrided by the duration parameter.
  337. @since v0.99.0
  338. */
  339. +(id) actionWithDuration:(ccTime)duration animation:(CCAnimation*)animation restoreOriginalFrame:(BOOL)b;
  340. /** initializes an action with a duration, animation and depending of the restoreOriginalFrame, it will restore the original frame or not.
  341. The 'delay' parameter of the animation will be overrided by the duration parameter.
  342. @since v0.99.0
  343. */
  344. -(id) initWithDuration:(ccTime)duration animation:(CCAnimation*)animation restoreOriginalFrame:(BOOL)b;
  345. @end