2011-04-06 81 views
4

这是我在CCTouchesMoved中用于在触摸位置产生粒子效果的代码。但是在使用这种FPS的同时,触摸正在向下移动到20!我已经尝试降低粒子的寿命和持续时间(你可以在代码中看到).....在CCTouchesMoved中使用Cocos2D粒子效果时FPS降低问题

如何解决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; 
} 

请帮我...我试着用不同的颗粒&最大限度地减少生命和持续时间,但没有工作! 任何新的想法?或修复我所做的事情?

+0

您使用模拟器? – xuanweng 2011-04-07 01:53:06

+0

@ xuanweng->我试了模拟器和设备。工作原理相同。 FPS在接触移动时显示约20。应用DID不是崩溃,但FPS降低。 – ShinuShajahan 2011-04-07 07:43:15

回答

4

我高度怀疑减速的原因是因为每次触摸移动时都会实例化一个新的CCParticleSystemQuad。为什么不只是初始化它曾经在initccTouchesBegan方法,但只设置在ccTouchesMoved位置和emissionRate:

- (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; 
} 
+0

哇!是啊!你是对的!现在它工作如此顺利! fps甚至不低于55!谢谢一堆!谢谢...这真的是一个很好的帮助.... :) – ShinuShajahan 2011-04-11 06:31:43

+0

也当我试图增加2000以上的排放率(只是出于好奇心和更多的视觉效果,没有我的迫切需要!)fps降低了位35-40左右。有没有其他方法可以解决这个问题? (不是很紧急!) – ShinuShajahan 2011-04-11 06:38:32

+1

我认为这就像已经达到了iPhone 4的极限......也许你需要满足于35-40 fps,或者只是等待iPhone 5:更好的建议是等待iPhone 5:P – Lukman 2011-04-11 08:09:27