我假设,ParticleEffect 中的所有发射器都具有相同的持续时间:
ParticleEffectPool.PooledEffect effect = particleEffectPool.obtain();
effect.reset();
effect.setPosition(posnX,posnY);
//divide by 1000 to convert from ms to seconds
float effectDuration = effect.getEmitters().first().duration / 1000f;
float skipProgress = 0.5f;
effect.update(skipProgress * effectDuration);
请注意,如果发射器具有不同的持续时间,您可能需要选择最大持续时间。此外,如果您的发射器有延迟,您也应该将其考虑在内。
更新
如果某些效果的属性随时间发生变化,这种方法将无法按预期工作。因此,如果您跳过其持续时间的一半,您就不会考虑之前发生的所有更改。你只是从某个状态开始。
例如,假设效果的持续时间 = 10,前 4 秒的速度为 100,之后速度为 0。如果您调用 effect.update(5),即跳过前 5 秒,粒子将具有速度= 0,他们只是不会“知道”,他们必须在前 4 秒内移动。
所以,我想这里唯一的解决方法是在循环中用小步骤更新效果,而不是一次调用只更新一半的持续时间:
ParticleEffectPool.PooledEffect effect = particleEffectPool.obtain();
effect.reset();
effect.setPosition(posnX,posnY);
//divide by 1000 to convert from ms to seconds
float skipDuration = 0.5f * effect.getEmitters().first().duration / 1000f;
//I guess, to reduce number of iterations in a loop, you can safely use
//a bit bigger stepDeltaTime, like 1 / 10f or bigger, but it depends on you effect;
//here I just use standard frame duration
final float stepDeltaTime = 1 / 60f;
while (skipDuration > 0) {
float dt = skipDuration < stepDeltaTime ? skipDuration : stepDeltaTime;
effect.update(dt);
skipDuration -= stepDeltaTime;
}