dziemich
dziemich

Reputation: 1

libgdx, moving a list of sprites horizontally

in my game, I am trying to make a list of sprites move horizontally. Here is my render method:

public void render() {
        Gdx.gl.glClearColor(255, 255, 255, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        int speed = 3;
        ConveyorBelt cnb = new ConveyorBelt();
        for (int i = 0; i < 6; i++) {
            Sprite s = new Sprite(img);
            s.setPosition(500 - 100 * i, 100);
            cnb.belt.push(s);
        }
        batch.begin();
        for (Sprite s : cnb.belt) {
            s.draw(batch);
            s.setX(s.getX() + speed);
        }
        batch.end();
    }

I want one of the sprites from the list to disappear, once hitting a certain point on the screen. Unfortunately, they dont seem to move. What is the reason fot that?

Thanks in advance!

Upvotes: 0

Views: 148

Answers (1)

Tenfour04
Tenfour04

Reputation: 93639

You're creating a brand new list of sprites every time render() is called. They all start at the initial positions you gave them, regardless of what you did to the sprites from the previous frame that are now all gone.

Move your new ConveyorBelt() and Sprite creation loop into create().

Upvotes: 2

Related Questions