Since I’m receiving questions about the particle system I used in my FluidToy 2 quite often lately, I thought I just release the sources here.
The particle system is based on a CCNode and works similar to the existing Cocos2D particle systems. The main difference is, that you can control the position and velocity of each particle. Please note that this system is not very optimized and lacks in flexibility since I just built it for FluidToy 2 and it was never meant to be more general. In other words: The code is a bit dirty! But feel free to play around with it, modify it and make use of it (and let me know what you’re making out of it).
There are two different systems: The SimpleParticleSystem, which draws points of any size or a point sprite using a texture. The second one is a LineParticleSystem, which will draw line particles. If you initialize the system with a size of 1000, you’ll have 500 lines, because a line consists out of 2 points (Wow, you never imagined that, did you? ;)). So if you loop through the particles, be sure to move only every second particle, the other one will follow with a small delay.
Download: Cocos2DSimpleParticleSystem
It works like every other CCNode:
particles = [SimpleParticleSystem node]; [particles initialize: 1000 width: size.width height: size.height]; [particles setTextureByString: @"particle_small.png"]; [self addChild: particles]; Loop through particles: while(count < particles.particleCount) { p = &particleAr[count]; p->dir.x += CCRANDOM_MINUS1_1(); p->dir.y += CCRANDOM_MINUS1_1(); ++count; ... }
Have fun!















