1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

libGDXで背景を自動スクロールさせる

Last updated at Posted at 2018-07-15

方法

ParallaxBackground から、ParallaxBackground.javaParallaxLayer.java をまるっとコピーします。
そのあとゲーム画面で背景をスクロールさせるコードを書きます。

ゲーム画面

横スクロールの場合、横スクロール速度 1.0f、縦スクロール速度 0.0fという感じで、背景のサイズに合わせてうまく調整してください。
一番最後の new Vector2(0,100) は、横スクロールなら1番目の数字を変えて2番目は0にしてください。ここの数字もいじるとスクロールの速度が変えられます。

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(横スクロール速度, 縦スクロール速度), new Vector2(0, 0)),},
                背景の横幅, 背景の高さ, new Vector2(0, 100));
} 

public void render(float delta){
rbg.render(Gdx.graphics.getDeltaTime());
}

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?