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

标签 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;
}

请帮帮我……我尝试了不同的粒子并尽量减少了生命周期和持续时间,但没有成功! 对此有什么新想法吗?或修复我所做的事情?

最佳答案

我高度怀疑速度变慢的原因是每次触摸移动时您都在实例化一个新的 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;
}

关于iphone - 在 CCTouchesMoved 中使用 Cocos2D 粒子效果时 FPS 降低问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5561531/

相关文章:

iphone - iPhone 的 GameCentre 成就问题

iphone - 如何将cocos2d添加到当前项目中?

ios - UIView 约束在使用 iPhone X 时表现不同

c# - 我可以使用 MonoTouch 将旧的 C# 桌面应用程序移植到 iPad 上吗?

objective-c - UIBarButtonItems 无法从一个工具栏中删除并添加到另一个工具栏?

objective-c - 使用分段控件的 TableView 可重用性

ios - 如何在cocos3D场景中添加2D Sprite 动画?

iphone - 我可以检查 iPhone 是否已插接吗?

iphone - 应用程序不允许访问UDID,并且不得使用UIDevice的uniqueIdentifier方法

ios - 如何将 ImageView 颜色设置为文本字段背景颜色