Reputation: 4721
I'm using a Particle system that follows a ball. As the ball is moving the Particle effects seems too follow too slowly the sprite.
I'm declearing the particle in such way:
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));
And setting the center in the touch event (on touch move):
ballEmitter.setCenter(newX-15, newY);
Is there a way to reduce the latency of the particle system ?
Upvotes: 1
Views: 1460
Reputation: 3322
Extend the PhysicsConnector class and override the onUpdate method. Set the center of emitter in the on update method. So the emitter position gets updated every time the Sprite's position gets updated to the Body's values.
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());
}
}
Make sure that when you connect the Ball's body to its sprite you pass in an instance of MyPhysicsConnector
physicsWorld.registerPhysicsConnector(new MyPhysicsConnector(ballSprite, ballBody, true, true));
Upvotes: 2