4

This is the code I have been using in CCTouchesMoved for producing Particle Effects in the touching locations. But while using this FPS is dropping to 20 while touches is moving! I have tried lowering the life and duration of particles (you can see that in code).....

How can I fix that FPS lowering issue on touches moved while using particle effects???

- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{   
    UITouch *touch = [touches anyObject];
    location = [touch locationInView:[touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];

    swipeEffect = [CCParticleSystemQuad particleWithFile:@"comet.plist"];

    //Setting some parameters for the effect
    swipeEffect.position = ccp(location.x, location.y);

    //For fixing the FPS issue I deliberately lowered the life & duration
    swipeEffect.life =0.0000000001;
    swipeEffect.duration = 0.0000000001;

    //Adding and removing after effects
    [self addChild:swipeEffect];
    swipeEffect.autoRemoveOnFinish=YES;
}

Please help me out... I tried with different particles & minimizing the life and duration, but didn't work! Any new ideas for that ? or fixes for what I have done?

P.J.Radadiya
  • 1,493
  • 1
  • 12
  • 21
ShinuShajahan
  • 1,296
  • 2
  • 11
  • 20

1 Answers1

4

I highly suspect the reason for the slowdown is because you are instantiating a new CCParticleSystemQuad every time the touch moves. Why not just instantiate it once in the init or ccTouchesBegan method but only set the position and emissionRate in ccTouchesMoved:

- (id)init {
   ...

   swipeEffect = [CCParticleSystemQuad particleWithFile:@"comet.plist"];
   swipeEffect.emissionRate = 0;
   [self addChild:swipeEffect];

   ...
}

- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   swipeEffect.emissionRate = 10;
}

- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   UITouch *touch = [touches anyObject];
   CGPoint location = [touch locationInView:[touch view]];
   location = [[CCDirector sharedDirector] convertToGL:location];
   swipeEffect.position = location;
}

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   swipeEffect.emissionRate = 0;
}
Lukman
  • 18,462
  • 6
  • 56
  • 66
  • wow! yea! you are right! now it working so smooth! fps not even going below 55!!! Thanks a bunch! thank you... it is really a nice help.... :) – ShinuShajahan Apr 11 '11 at 06:31
  • also while I tried to increase the emissionRate above 2000 (just out of curiosity & for more visual effect, no urgent need of mine indeed!) fps lowered a bit around 35-40. Is there any other way to fix that too? (not urgent indeed!) – ShinuShajahan Apr 11 '11 at 06:38
  • 1
    I think that's like already hitting the limit for iPhone 4 ... maybe you need to be content with 35-40 fps, or just wait for iPhone 5 :P – Lukman Apr 11 '11 at 08:09
  • 1
    owh wait, a better suggestion is to use `CCParticleSystemPoint` .. although maybe the quality will be lowered a bit .. – Lukman Apr 11 '11 at 08:13
  • @Lukman-> nice suggestions... these are going to help me a lot... thanks again... :) now it's fixed. it worked well..thanks... :) – ShinuShajahan Apr 11 '11 at 09:14