FPS lowering issue while using Cocos2D Particle Effects in CCTouchesMoved
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 fi开发者_运维问答xes for what I have done?
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;
}
精彩评论