4

これは、私が 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;
}

助けてください...さまざまなパーティクルを使用して、寿命と期間を最小限に抑えようとしましたが、うまくいきませんでした! そのための新しいアイデアはありますか?または私がやったことの修正?

4

1 に答える 1

4

スローダウンの理由は、タッチが動くたびに新しい CCParticleSystemQuad をインスタンス化しているためだと強く思います。initorメソッドで一度インスタンス化するのではなくccTouchesBegan、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 に答える