我正在使用跟随球的粒子系统。当球在移动时,粒子效果似乎跟随精灵太慢了。
我以这种方式摧毁了粒子:
final CircleOutlineParticleEmitter ballEmitter = new CircleOutlineParticleEmitter(0, 0, 6);
final ParticleSystem particleBallSystem = new ParticleSystem(ballEmitter, 30, 30, 180, this.mParticleTextureRegion);
particleBallSystem.addParticleInitializer(new ColorInitializer(0, 0, 1));
particleBallSystem.addParticleInitializer(new AlphaInitializer(1));
particleBallSystem.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE);
particleBallSystem.addParticleInitializer(new VelocityInitializer(-2, 2, -2, 3));
particleBallSystem.addParticleInitializer(new RotationInitializer(0.0f, 180.0f));
particleBallSystem.addParticleModifier(new org.anddev.andengine.entity.particle.modifier.ScaleModifier(1.0f, 1.2f, 0, 5));
particleBallSystem.addParticleModifier(new ColorModifier(0, 0, 0.2f, 0.1f, 0, 1, 1, 3));
particleBallSystem.addParticleModifier(new ColorModifier(0, 0, 0.1f, 0.2f, 1, 1, 4, 6));
particleBallSystem.addParticleModifier(new AlphaModifier(0, 1, 0, 1));
particleBallSystem.addParticleModifier(new AlphaModifier(1, 0, 5, 6));
particleBallSystem.addParticleModifier(new ExpireModifier(1, 6));
在触摸事件中设置中心(触摸移动):
ballEmitter.setCenter(newX-15, newY);
有没有办法减少粒子系统的延迟?
答案 0 :(得分:2)
扩展PhysicsConnector类并覆盖onUpdate方法。在on update方法中设置发射器的中心。因此,每次Sprite的位置更新为Body的值时,发射器位置都会更新。
class MyPhysicsConnector extends PhysicsConnector
{
public MyPhysicsConnector(IAreaShape pAreaShape, Body pBody, boolean pUdatePosition, boolean pUpdateRotation)
{
super(pAreaShape, pBody, pUdatePosition, pUpdateRotation);
}
@Override
public void onUpdate(float pSecondsElapsed)
{
super.onUpdate(pSecondsElapsed);
final IShape shape = this.mShape;
ballEmitter.setCenter(shape.getX(), shape.getY());
}
}
确保在将Ball的主体连接到其精灵时传入MyPhysicsConnector的实例
physicsWorld.registerPhysicsConnector(new MyPhysicsConnector(ballSprite, ballBody, true, true));