Skip to content

Instantly share code, notes, and snippets.

@Nub
Created October 30, 2011 18:39
Show Gist options
  • Select an option

  • Save Nub/1326249 to your computer and use it in GitHub Desktop.

Select an option

Save Nub/1326249 to your computer and use it in GitHub Desktop.
self.particles = [NSMutableArray array];
minimumLife = 3.0;
maximumLife = 10.0;
minimumParticles = 100;
maximumParticles = 250;
_deadParticles = (NSInteger*)malloc(sizeof(NSInteger) * maximumParticles);
_deadParticleCount = maximumParticles;
for (NSInteger i = 0; i < maximumParticles; i++) {//Cache all particles for speed
_deadParticles[i] = i;
ZParticle *particle = [[ZParticle alloc] init];
[self.particles addObject:particle];
[particle release];
}
//used later in emit particles to snag an object to edit is properties
- (ZParticle*)getDeadParticle{
NSInteger index = _deadParticles[--_deadParticleCount];//pull from the tail
return [self.particles objectAtIndex:index];
}
//used later in render object to setup rendering data and this is where the data is corrupt
for (ZParticle *particle in self.particleEmitter.particles) {
if ([particle isAlive]) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment