Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

How do I increase or decrease the background movement speed (libgdx) [on hold]

$
0
0

I making a game using libgdx and I want to know how to increase or decrease the background movement speed

this is what i tried

 public class PlayState extends State {


private int tubeSpacing = 125;

private int tubeCount = 4;


private Protagonist bird;
private Texture bg;

GestureDetector gestureDetector;

private Array<Primary_Obstacle> tubes;


public PlayState(GameStateManager gsm) {
    super(gsm);



    bird = new Protagonist(50, 300);  //MySGame.WIDTH/2 - 50/2/* width of bird(to pos in middle) */ ,MySGame.HEIGHT/2);
    cam.setToOrtho(false, MySGame.WIDTH / 2, MySGame.HEIGHT / 2);
    bg = new Texture("testBackground.png");

    tubes = new Array<Primary_Obstacle>();

    for (int i = 1; i <= tubeCount; i++) {

        tubes.add(new Primary_Obstacle(i * (tubeSpacing + Primary_Obstacle.tubeWidth)));
    }


}

@Override
protected void handleInput() {




}


@Override
public void update(float dt) {


    handleInput();
    bird.update(dt);
    cam.position.x = bird.getPosition().x + 80;

    for (Primary_Obstacle tube : tubes) {

        if (cam.position.x - (cam.viewportWidth / 2) > tube.getPostopTube().x + tube.getTopTube().getWidth()) {

            tube.reposition(tube.getPosbotTube().x + ((tube.tubeWidth + tubeSpacing) * tubeCount));
        }
    }

    cam.update();

}


@Override
public void render(SpriteBatch sb) {

    sb.setProjectionMatrix(cam.combined); // to initiate cam
    sb.begin();
    sb.draw(bg, cam.position.x - (cam.viewportWidth / 2), 0);
    sb.draw(bird.getTexture(), bird.getPosition().x, bird.getPosition().y);
    for (Primary_Obstacle tube : tubes) {
        sb.draw(tube.getTopTube(), tube.getPostopTube().x,      tube.getPostopTube().y);
        sb.draw(tube.getBottomTube(), tube.getPosbotTube().x, tube.getPosbotTube().y);
    }


    sb.end();

}

@Override
public void dispose() {









}
 }

***please ignore any irrelevant parts*


Viewing all articles
Browse latest Browse all 434

Trending Articles