在CCTouchesMoved中使用Cocos2D粒子效果时FPS降低问题

时间:2011-04-06 04:40:08

标签: iphone objective-c cocos2d-iphone particle-system

这是我在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;
}

请帮帮我......我尝试过不同的颗粒&最小化生命和持续时间,但没有奏效! 有什么新想法吗?或修复我所做的事情?

1 个答案:

答案 0 :(得分: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;
}