Created
January 9, 2014 19:39
-
-
Save Ben-G/8340545 to your computer and use it in GitHub Desktop.
Example of creating a particle effect in cocos2d 3.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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