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