4

这是我在 CCTouchesMoved 中使用的代码,用于在触摸位置产生粒子效果。但是,在使用此 FPS 时,当触摸移动时,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;
}

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

4

1 回答 1

4

我高度怀疑速度变慢的原因是因为每次触摸移动时您都在实例化一个新的 CCParticleSystemQuad。为什么不只在initorccTouchesBegan方法中实例化一次,而只在 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;
}
于 2011-04-11T04:34:39.547 回答