和引擎。粒子效果跟随精灵的速度太慢。如何减少延迟

发布于 2025-01-05 10:39:54 字数 1340 浏览 0 评论 0原文

我正在使用跟随球的粒子系统。当球移动时,粒子效果似乎跟随精灵的速度太慢。

我以这种方式清除粒子:

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);

有没有办法减少粒子系统的延迟?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心安伴我暖 2025-01-12 10:39:54

扩展PhysicsConnector类并重写onUpdate方法。在 on update 方法中设置发射器的中心。因此,每次精灵的位置更新为主体的值时,发射器位置都会更新。

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());
    }
}

确保当您将球的主体连接到其精灵时,您传递了 MyPhysicsConnector 的实例

physicsWorld.registerPhysicsConnector(new MyPhysicsConnector(ballSprite, ballBody, true, true));

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));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文