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

发布于 10-31 06:07 字数 919 浏览 3 评论 0原文

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

渔村楼浪2024-11-07 06:07:02

我高度怀疑速度减慢的原因是因为每次触摸移动时您都会实例化一个新的 CCParticleSystemQuad。为什么不在 initccTouchesBegan 方法中实例化一次,而只在 ccTouchesMoved 中设置position和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;
}

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 or ccTouchesBegan method but only set the position and emissionRate in 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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文