Libgdx 无法使用更新方法更改ParticleEffect的位置

Libgdx 无法使用更新方法更改ParticleEffect的位置,libgdx,Libgdx,我正在开发一款flappy bird风格的侧滚游戏,目前正在为主要精灵提供可收集的物品,以便其在飞行时收集。我不是移动主精灵,而是使用视差效应移动背景,并打算将收藏品(称为球体)移向主精灵(鸟)。球体以随机位置渲染,但即使在调用update方法后,位置也不会更改 这是我的收藏品orbs.java public class CollectibleOrbs { private static final int ORB_COUNT = 10; private Array<Orb&

我正在开发一款flappy bird风格的侧滚游戏,目前正在为主要精灵提供可收集的物品,以便其在飞行时收集。我不是移动主精灵,而是使用视差效应移动背景,并打算将收藏品(称为球体)移向主精灵(鸟)。球体以随机位置渲染,但即使在调用update方法后,位置也不会更改

这是我的收藏品orbs.java

public class CollectibleOrbs {
    private static final int ORB_COUNT = 10;
    private Array<Orb> orbs;
    private Orb orb;

    public CollectibleOrbs(){
        orbs = new Array<Orb>();

        for(int i=0;i<ORB_COUNT; i++) {
            orb = new Orb();
            orbs.add(orb);
        }
     }

    public void update(float delta){
        for(Orb orb: orbs){
            orb.update(delta);
        }
    }

    public void render(SpriteBatch sb){
        for(Orb orb:orbs){
            orb.draw(sb);
        }
    }

    private class Orb{
        private ParticleEffect effect;
        private Vector2 position;
        private Random rand;


        public Orb(){
             effect = new ParticleEffect();
             rand = new Random();
             position = new Vector2(rand.nextInt(Gdx.graphics.getWidth()),rand.nextInt(Gdx.graphics.getHeight()));
             effect.load(Gdx.files.internal("particle/orbred.p"),
                               Gdx.files.internal("particle"));
             effect.setPosition(position.x,position.y);
         }

        public void draw(SpriteBatch sb){
             effect.draw(sb,Gdx.graphics.getDeltaTime());
        }

        public void update(float dt){
            if(position.x< 10){
                position.x = rand.nextInt(Gdx.graphics.getWidth());
                position.y = rand.nextInt(Gdx.graphics.getHeight());
            }
            else
            {
                position.x-= 100*dt;
            }
        }
     }
 }
公共类收藏品RBS{
私有静态最终int ORB_计数=10;
专用阵列球体;
私人球体;
公共收藏品RBS(){
orbs=新数组();

对于(int i=0;i而言,问题在于
位置
效果
向量无关。仅改变
位置
不会改变
效果的
位置。解决方法之一:

public void update(float dt){
    if(position.x< 10){
        position.x = rand.nextInt(Gdx.graphics.getWidth());
        position.y = rand.nextInt(Gdx.graphics.getHeight());
    }
    else
    {
        position.x-= 100*dt;
    }
    // you should update ParticleEffect position too, just like you did in the constructor
    effect.setPosition(position.x, position.y); 
}
公共作废更新(浮动dt){
如果(位置x<10){
position.x=rand.nextInt(Gdx.graphics.getWidth());
position.y=rand.nextInt(Gdx.graphics.getHeight());
}
其他的
{
位置x-=100*dt;
}
//您也应该更新ParticleEffect位置,就像在构造函数中一样
作用。设定位置(位置x,位置y);
}