• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

/depot/cocosdocs/cocos2d-iphone-0.99.5/cocos2d/CCParticleSystem.h

00001 /*
00002  * cocos2d for iPhone: http://www.cocos2d-iphone.org
00003  *
00004  * Copyright (c) 2008-2010 Ricardo Quesada
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a copy
00007  * of this software and associated documentation files (the "Software"), to deal
00008  * in the Software without restriction, including without limitation the rights
00009  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010  * copies of the Software, and to permit persons to whom the Software is
00011  * furnished to do so, subject to the following conditions:
00012  * 
00013  * The above copyright notice and this permission notice shall be included in
00014  * all copies or substantial portions of the Software.
00015  * 
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00022  * THE SOFTWARE.
00023  *
00024  */
00025 
00026 
00027 #import "CCProtocols.h"
00028 #import "CCNode.h"
00029 #import "ccTypes.h"
00030 #import "ccConfig.h"
00031 
00032 #if CC_ENABLE_PROFILERS
00033 @class CCProfilingTimer;
00034 #endif
00035 
00036 //* @enum
00037 enum {
00039          kCCParticleDurationInfinity = -1,
00040 
00042          kCCParticleStartSizeEqualToEndSize = -1,
00043          
00045          kCCParticleStartRadiusEqualToEndRadius = -1,
00046 
00047          // backward compatible
00048          kParticleStartSizeEqualToEndSize = kCCParticleStartSizeEqualToEndSize,
00049          kParticleDurationInfinity = kCCParticleDurationInfinity,
00050 };
00051 
00052 //* @enum
00053 enum {
00055          kCCParticleModeGravity,
00056          
00058          kCCParticleModeRadius,     
00059 };
00060 
00061 
00065 typedef enum {
00067          kCCPositionTypeFree,
00068 
00072          kCCPositionTypeRelative,
00073          
00075          kCCPositionTypeGrouped,
00076 }tCCPositionType;
00077 
00078 // backward compatible
00079 enum {
00080          kPositionTypeFree = kCCPositionTypeFree,
00081          kPositionTypeGrouped = kCCPositionTypeGrouped,
00082 }; 
00083 
00087 typedef struct sCCParticle {
00088          CGPoint           pos;
00089          CGPoint           startPos;
00090 
00091          ccColor4F         color;
00092          ccColor4F         deltaColor;
00093 
00094          float             size;
00095          float             deltaSize;
00096 
00097          float             rotation;
00098          float             deltaRotation;
00099 
00100          ccTime            timeToLive;
00101 
00102          union {
00103                   // Mode A: gravity, direction, radial accel, tangential accel
00104                   struct {
00105                            CGPoint           dir;
00106                            float             radialAccel;
00107                            float             tangentialAccel;
00108                   } A;
00109          
00110                   // Mode B: radius mode
00111                   struct {
00112                            float             angle;
00113                            float             degreesPerSecond;
00114                            float             radius;
00115                            float             deltaRadius;
00116                   } B;
00117          } mode;
00118 
00119 }tCCParticle;
00120 
00121 typedef void (*CC_UPDATE_PARTICLE_IMP)(id, SEL, tCCParticle*, CGPoint);
00122 
00123 @class CCTexture2D;
00124 
00168 @interface CCParticleSystem : CCNode <CCTextureProtocol>
00169 {        
00170          // is the particle system active ?
00171          BOOL active;
00172          // duration in seconds of the system. -1 is infinity
00173          float duration;
00174          // time elapsed since the start of the system (in seconds)
00175          float elapsed;
00176          
00177          // position is from "superclass" CocosNode
00178          CGPoint sourcePosition;
00179          // Position variance
00180          CGPoint posVar;
00181          
00182          // The angle (direction) of the particles measured in degrees
00183          float angle;
00184          // Angle variance measured in degrees;
00185          float angleVar;
00186          
00187          // Different modes
00188          
00189          NSInteger emitterMode_;
00190          union {
00191                   // Mode A:Gravity + Tangential Accel + Radial Accel
00192                   struct {
00193                            // gravity of the particles
00194                            CGPoint gravity;
00195 
00196                            // The speed the particles will have.
00197                            float speed;
00198                            // The speed variance
00199                            float speedVar;
00200 
00201                            // Tangential acceleration
00202                            float tangentialAccel;
00203                            // Tangential acceleration variance
00204                            float tangentialAccelVar;
00205 
00206                            // Radial acceleration
00207                            float radialAccel;
00208                            // Radial acceleration variance
00209                            float radialAccelVar;
00210                            } A;
00211 
00212                   // Mode B: circular movement (gravity, radial accel and tangential accel don't are not used in this mode)
00213                   struct {
00214          
00215                            // The starting radius of the particles
00216                            float startRadius;
00217                            // The starting radius variance of the particles
00218                            float startRadiusVar;
00219                            // The ending radius of the particles
00220                            float endRadius;
00221                            // The ending radius variance of the particles
00222                            float endRadiusVar;                          
00223                            // Number of degress to rotate a particle around the source pos per second
00224                            float rotatePerSecond;
00225                            // Variance in degrees for rotatePerSecond
00226                            float rotatePerSecondVar;
00227                   } B;
00228          } mode;
00229          
00230          // start ize of the particles
00231          float startSize;
00232          // start Size variance
00233          float startSizeVar;
00234          // End size of the particle
00235          float endSize;
00236          // end size of variance
00237          float endSizeVar;
00238          
00239          // How many seconds will the particle live
00240          float life;
00241          // Life variance
00242          float lifeVar;
00243          
00244          // Start color of the particles
00245          ccColor4F startColor;
00246          // Start color variance
00247          ccColor4F startColorVar;
00248          // End color of the particles
00249          ccColor4F endColor;
00250          // End color variance
00251          ccColor4F endColorVar;
00252          
00253          // start angle of the particles
00254          float startSpin;
00255          // start angle variance
00256          float startSpinVar;
00257          // End angle of the particle
00258          float endSpin;
00259          // end angle ariance
00260          float endSpinVar;
00261          
00262          
00263          // Array of particles
00264          tCCParticle *particles;
00265          // Maximum particles
00266          NSUInteger totalParticles;
00267          // Count of active particles
00268          NSUInteger particleCount;
00269          
00270          // color modulate
00271 //       BOOL colorModulate;
00272          
00273          // How many particles can be emitted per second
00274          float emissionRate;
00275          float emitCounter;
00276          
00277          // Texture of the particles
00278          CCTexture2D *texture_;
00279          // blend function
00280          ccBlendFunc       blendFunc_;
00281 
00282          // movment type: free or grouped
00283          tCCPositionType   positionType_;
00284 
00285          // Whether or not the node will be auto-removed when there are not particles
00286          BOOL     autoRemoveOnFinish_;
00287 
00288          //  particle idx
00289          NSUInteger particleIdx;
00290          
00291          // Optimization
00292          CC_UPDATE_PARTICLE_IMP     updateParticleImp;
00293          SEL                                                   updateParticleSel;
00294          
00295 // profiling
00296 #if CC_ENABLE_PROFILERS
00297          CCProfilingTimer* _profilingTimer;
00298 #endif
00299 }
00300 
00302 @property (nonatomic,readonly) BOOL active;
00304 @property (nonatomic,readonly) NSUInteger    particleCount;
00306 @property (nonatomic,readwrite,assign) float duration;
00308 @property (nonatomic,readwrite,assign) CGPoint sourcePosition;
00310 @property (nonatomic,readwrite,assign) CGPoint posVar;
00312 @property (nonatomic,readwrite,assign) float life;
00314 @property (nonatomic,readwrite,assign) float lifeVar;
00316 @property (nonatomic,readwrite,assign) float angle;
00318 @property (nonatomic,readwrite,assign) float angleVar;
00319 
00321 @property (nonatomic,readwrite,assign) CGPoint gravity;
00323 @property (nonatomic,readwrite,assign) float speed;
00325 @property (nonatomic,readwrite,assign) float speedVar;
00327 @property (nonatomic,readwrite,assign) float tangentialAccel;
00329 @property (nonatomic,readwrite,assign) float tangentialAccelVar;
00331 @property (nonatomic,readwrite,assign) float radialAccel;
00333 @property (nonatomic,readwrite,assign) float radialAccelVar;
00334 
00336 @property (nonatomic,readwrite,assign) float startRadius;
00338 @property (nonatomic,readwrite,assign) float startRadiusVar;
00340 @property (nonatomic,readwrite,assign) float endRadius;
00342 @property (nonatomic,readwrite,assign) float endRadiusVar;                       
00344 @property (nonatomic,readwrite,assign) float rotatePerSecond;
00346 @property (nonatomic,readwrite,assign) float rotatePerSecondVar;
00347 
00349 @property (nonatomic,readwrite,assign) float startSize;
00351 @property (nonatomic,readwrite,assign) float startSizeVar;
00353 @property (nonatomic,readwrite,assign) float endSize;
00355 @property (nonatomic,readwrite,assign) float endSizeVar;
00357 @property (nonatomic,readwrite,assign) ccColor4F startColor;
00359 @property (nonatomic,readwrite,assign) ccColor4F startColorVar;
00361 @property (nonatomic,readwrite,assign) ccColor4F endColor;
00363 @property (nonatomic,readwrite,assign) ccColor4F endColorVar;
00364 //* initial angle of each particle
00365 @property (nonatomic,readwrite,assign) float startSpin;
00366 //* initial angle of each particle
00367 @property (nonatomic,readwrite,assign) float startSpinVar;
00368 //* initial angle of each particle
00369 @property (nonatomic,readwrite,assign) float endSpin;
00370 //* initial angle of each particle
00371 @property (nonatomic,readwrite,assign) float endSpinVar;
00373 @property (nonatomic,readwrite,assign) float emissionRate;
00375 @property (nonatomic,readwrite,assign) NSUInteger totalParticles;
00377 @property (nonatomic,readwrite, retain) CCTexture2D * texture;
00379 @property (nonatomic,readwrite) ccBlendFunc blendFunc;
00387 @property (nonatomic,readwrite) BOOL blendAdditive;
00391 @property (nonatomic,readwrite) tCCPositionType positionType;
00396 @property (nonatomic,readwrite) BOOL autoRemoveOnFinish;
00401 @property (nonatomic,readwrite) NSInteger emitterMode;
00402 
00408 +(id) particleWithFile:(NSString*)plistFile;
00409 
00415 -(id) initWithFile:(NSString*) plistFile;
00416 
00420 -(id) initWithDictionary:(NSDictionary*)dictionary;
00421 
00423 -(id) initWithTotalParticles:(int) numberOfParticles;
00425 -(BOOL) addParticle;
00427 -(void) initParticle: (tCCParticle*) particle;
00429 -(void) stopSystem;
00431 -(void) resetSystem;
00433 -(BOOL) isFull;
00434 
00436 -(void) updateQuadWithParticle:(tCCParticle*)particle newPosition:(CGPoint)pos;
00438 -(void) postStep;
00439 
00441 -(void) update: (ccTime) dt;
00442 
00443 @end
00444 

Generated on Mon Jan 31 2011 15:39:14 for Unofficial Cocos2D for iOS 0.99.5 API Reference by  doxygen 1.7.1