Skip to content

Instantly share code, notes, and snippets.

@Ben-G
Created January 9, 2014 19:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Ben-G/8340545 to your computer and use it in GitHub Desktop.
Save Ben-G/8340545 to your computer and use it in GitHub Desktop.
Example of creating a particle effect in cocos2d 3.0
- (CCParticleSystem *)createParticleEffectInCode {
CCParticleSystem *emitter = [[CCParticleSystem alloc] initWithTotalParticles:50];
emitter.texture = [[CCTextureCache sharedTextureCache] addImage: @"stars-grayscale.png"];
// duration
emitter.duration = CCParticleSystemDurationInfinity;
// Gravity Mode: gravity
emitter.gravity = CGPointZero;
// Set "Gravity" mode (default one)
emitter.emitterMode = CCParticleSystemModeGravity;
// Gravity Mode: speed of particles
emitter.speed = 160;
emitter.speedVar = 20;
// Gravity Mode: radial
emitter.radialAccel = -120;
emitter.radialAccelVar = 0;
// Gravity Mode: tagential
emitter.tangentialAccel = 30;
emitter.tangentialAccelVar = 0;
// angle
emitter.angle = 90;
emitter.angleVar = 360;
// emitter position
emitter.position = ccp(160,240);
emitter.posVar = CGPointZero;
// life of particles
emitter.life = 4;
emitter.lifeVar = 1;
// spin of particles
emitter.startSpin = 0;
emitter.startSpinVar = 0;
emitter.endSpin = 0;
emitter.endSpinVar = 0;
// color of particles
emitter.startColor = [CCColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1];
emitter.startColorVar = [CCColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1];
emitter.endColor = [CCColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:0.2];
emitter.endColorVar = [CCColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:0.2];
// size, in pixels
emitter.startSize = 80.0f;
emitter.startSizeVar = 40.0f;
emitter.endSize = CCParticleSystemStartSizeEqualToEndSize;
// emits per second
emitter.emissionRate = emitter.totalParticles/emitter.life;
// additive
emitter.blendAdditive = YES;
return emitter;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment