I'm getting different results with setCenterOfGravity and setPosition. setPosition gives the correct position and the former being at a certain offset. Any idea why?
Optimize ParticleSystems
(66 posts) (22 voices)-
Posted 1 year ago #
-
As an aside, is there a way to get particles running on a CCSpriteBatchNode? This causes me no end of trouble.
Posted 12 months ago # -
hi,
i use zombie's method to spawn the particles.
recently i updated from ver 0.99.4 to the latest version (1.0.0-rc3).
in the new version, particles are spawning when they should not.here's the update and the spawn methods
-(void) update: (ccTime) dt { if( active && emissionRate ) { float rate = 1.0f / emissionRate; emitCounter += dt; while( particleCount < totalParticles && emitCounter > rate ) { [self addParticle]; emitCounter -= rate; } elapsed += dt; if(duration != -1 && duration < elapsed) [self stopSystem]; } particleIdx = 0; #if CC_ENABLE_PROFILERS CCProfilingBeginTimingBlock(_profilingTimer); #endif CGPoint currentPosition = CGPointZero; if( positionType_ == kCCPositionTypeFree ) { currentPosition = [self convertToWorldSpace:CGPointZero]; currentPosition.x *= CC_CONTENT_SCALE_FACTOR(); currentPosition.y *= CC_CONTENT_SCALE_FACTOR(); } else if( positionType_ == kCCPositionTypeRelative ) { currentPosition = position_; currentPosition.x *= CC_CONTENT_SCALE_FACTOR(); currentPosition.y *= CC_CONTENT_SCALE_FACTOR(); } while( particleIdx < particleCount ) { tCCParticle *p = &particles[particleIdx]; // life p->timeToLive -= dt; //if( p->timeToLive > 0 ) { // Mode A: gravity, direction, tangential accel & radial accel if( emitterMode_ == kCCParticleModeGravity ) { CGPoint tmp, radial, tangential; radial = CGPointZero; // radial acceleration if(p->pos.x || p->pos.y) radial = ccpNormalize(p->pos); tangential = radial; radial = ccpMult(radial, p->mode.A.radialAccel); // tangential acceleration float newy = tangential.x; tangential.x = -tangential.y; tangential.y = newy; tangential = ccpMult(tangential, p->mode.A.tangentialAccel); // (gravity + radial + tangential) * dt tmp = ccpAdd( ccpAdd( radial, tangential), mode.A.gravity); tmp = ccpMult( tmp, dt); p->mode.A.dir = ccpAdd( p->mode.A.dir, tmp); tmp = ccpMult(p->mode.A.dir, dt); p->pos = ccpAdd( p->pos, tmp ); } // Mode B: radius movement else { // Update the angle and radius of the particle. p->mode.B.angle += p->mode.B.degreesPerSecond * dt; p->mode.B.radius += p->mode.B.deltaRadius * dt; p->pos.x = - cosf(p->mode.B.angle) * p->mode.B.radius; p->pos.y = - sinf(p->mode.B.angle) * p->mode.B.radius; } // color p->color.r += (p->deltaColor.r * dt); p->color.g += (p->deltaColor.g * dt); p->color.b += (p->deltaColor.b * dt); p->color.a += (p->deltaColor.a * dt); // size p->size += (p->deltaSize * dt); p->size = MAX( 0, p->size ); // angle p->rotation += (p->deltaRotation * dt); // // update values in quad // CGPoint newPos; if( positionType_ == kCCPositionTypeFree || positionType_ == kCCPositionTypeRelative ) { CGPoint diff = ccpSub( currentPosition, p->startPos ); newPos = ccpSub(p->pos, diff); } else newPos = p->pos; updateParticleImp(self, updateParticleSel, p, newPos); // update particle counter particleIdx++; } // else { // // life < 0 // if( particleIdx != particleCount-1 ) // particles[particleIdx] = particles[particleCount-1]; // particleCount--; // // if( particleCount == 0 && autoRemoveOnFinish_ ) { // [self unscheduleUpdate]; // [parent_ removeChild:self cleanup:YES]; // return; // } // } } #if CC_ENABLE_PROFILERS CCProfilingEndTimingBlock(_profilingTimer); #endif #ifdef CC_USES_VBO [self postStep]; #endif } // do not mix spawn with addParticle (so also not with self emitting systems) - (void) spawnParticles:(uint)n { tCCParticle *particle; for(uint i=0; i<n; i++) { if(particlePos==totalParticles) { particlePos=0; } particle = &particles[ particlePos ]; [self initParticle: particle]; particlePos++; particleCount++; if(particleCount>totalParticles) { particleCount=totalParticles; } } }in the old version, particle apperad and faded out. in this version they are being created time after time.
can anyone point the change that was made, or why this is happening?thanks,
iradPosted 7 months ago # -
Hello,
This is a old thread and the code seems out of sync with the latest release of cocos2d-iphone. Does anybody know how to make this sharing/reusing of a ParticleSystem work with the "new" CCParticleSystemQuad class?
I really hope one of you wizards can help me here, I could really need some performance boost in my game particles.
Best regards and high hopes
SørenPosted 1 month ago #
Reply
You must log in to post.