在 CCTouchesMoved 中使用 Cocos2D 粒子效果时出现 FPS 降低问题
这是我在 CCTouchesMoved 中用于在触摸位置产生粒子效果的代码。但是,当使用此 FPS 时,触摸移动时会下降到 20!我尝试过降低粒子的寿命和持续时间(您可以在代码中看到)...
如何解决使用粒子效果时移动触摸时的 FPS 降低问题???
- (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;
}
请帮助我......我尝试使用不同的粒子和尽量减少寿命和持续时间,但没有用! 对此有什么新想法吗?或者修复我所做的事情?
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?
我高度怀疑速度减慢的原因是因为每次触摸移动时您都会实例化一个新的 CCParticleSystemQuad。为什么不在
init
或ccTouchesBegan
方法中实例化一次,而只在 ccTouchesMoved 中设置position和emissionRate: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
orccTouchesBegan
method but only set the position and emissionRate in ccTouchesMoved: