gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 19:42:54 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com