Libgdx background and foreground in single stage

后端 未结 1 1656
名媛妹妹
名媛妹妹 2020-12-20 04:10

My requirements:

  1. Background filling entire physical screen (stretching if required)
  2. Preserve aspect ratio of foreground assets (Work with virtual widt
相关标签:
1条回答
  • 2020-12-20 04:52

    You could use two stages, but for your case it would be better to just solve this problem by creating two groups inside a single stage:

    Stage stage = new Stage();
    
    Group background = new Group();
    background.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Group foreground = new Group();
    foreground.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    
    // Notice the order
    stage.addActor(background);
    stage.addActor(foreground);
    
    foreground.addActor(new Actor());
    // Or anything else you want to add like you normally would to the stage. 
    
    background.addActor(new Image()); // your background image here.
    
    Gdx.input.setInputProcessor(stage);
    
    0 讨论(0)
提交回复
热议问题