From ParallaxBackground, go to [ParallaxBackground.java](https://github.com/surahul/ParallaxBackground-libgdx/blob/master/core/src/com/ rahul / libgdx / parallax / ParallaxBackground.java) and ParallaxLayer.java Is copied in its entirety. Then write the code to scroll the background on the game screen.
For horizontal scrolling, ** horizontal scrolling speed ** 1.0f, ** vertical scrolling speed ** 0.0f, and adjust well according to the size of the background. For the last * new Vector2 (0,100) *, change the first number to 0 for horizontal scrolling. You can change the scroll speed by playing with the numbers here.
GameScreen.java
ParallaxBackground rbg;
public GameScreen(){
assets = new AssetManager();
assets.load("background.pack", TextureAtlas.class);
assets.finishLoading();
atlas = assets.get("background.pack");
rbg = new ParallaxBackground(new ParallaxLayer[]{
new ParallaxLayer(atlas.findRegion("background"),
new Vector2(Side-scrolling speed,Vertical scroll speed), new Vector2(0, 0)),},
Background width,Background height, new Vector2(0, 100));
}
public void render(float delta){
rbg.render(Gdx.graphics.getDeltaTime());
}
Recommended Posts