FPS lowering issue when using Cocos2D Particle effects in CCTouchesMoved

This is the code that I used in CCTouchesMoved to create particle effects in touching places. But when using this, the FPS drops to 20, so far as concerns the movements! I tried to reduce the life and duration of the particles (you can see this in the code) .....

How can I fix the problem of reducing FPS when moving 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 ... I tried with different particles and minimized life and duration, but it does not work! Any new ideas for this? or corrections for what i did?

+4
source share
1 answer

I very much suspect that the reason for the slowdown is that you create a new CCParticleSystemQuad every time the sensor moves. Why not just instantiate it once in the init or ccTouchesBegan , but just set the position and radiation 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; } 
+4
source

Source: https://habr.com/ru/post/1346857/


All Articles