【问题标题】:FPS lowering issue while using Cocos2D Particle Effects in CCTouchesMoved在 CCTouchesMoved 中使用 Cocos2D 粒子效果时 FPS 降低问题
【发布时间】:2011-04-06 04:40:08
【问题描述】:

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

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

【问题讨论】:

  • 你在用模拟器吗?
  • @xuanweng-> 我尝试了模拟器和设备。工作相同。触摸移动时 FPS 显示大约 20。应用程序没有崩溃,但 FPS 降低了。

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


【解决方案1】:

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

【讨论】:

  • 哇!是的!你说的对!现在它工作得如此顺利! fps甚至不会低于55!!!非常感谢!谢谢......这真的是一个很好的帮助...... :)
  • 当我尝试将emissionRate 提高到2000 以上时(只是出于好奇和更多视觉效果,我确实不需要!)fps 降低了大约35-40。还有其他方法可以解决这个问题吗? (确实不紧急!)
  • 我认为这就像已经达到 iPhone 4 的极限......也许你需要满足于 35-40 fps,或者只是等待 iPhone 5 :P
  • 等等,更好的建议是使用CCParticleSystemPoint ..虽然质量可能会降低一点..
  • @Lukman-> 不错的建议...这些对我有很大帮助...再次感谢... :) 现在它已修复。它运作良好..谢谢... :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-03
  • 1970-01-01
  • 2023-04-03
  • 2012-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多