Friday, May 10, 2024
HomeGame Developmentjava - How to setup position of an image overlayed another in...

java – How to setup position of an image overlayed another in a stack libgdx


I have tried to change the position of the image bagitem[i]( which items are covered by a green border square; it only used method debug() to appear the border) to center in many ways but have not been successful.
public void createBag() {

    // Table bagTable = new Table();
    bagTable.setFillParent(true);
    // Overlay image
    TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("Items/Weapons/Weapon.atlas"));
    for (int i = 0; i < 4; i++) {
        Stack stack = new Stack();
        Image BG = new Image(new Texture(Gdx.files.internal("Backgrounds/BG3.png")));
        BG.setScale(1f, 1f);
        stack.add(BG);

        TextureAtlas.AtlasRegion region = atlas.findRegion("AxeInHand");
        bagItems[i] = new Image(region);
        bagItems[i].setScale(0.75f, 0.75f);
        stack.add(bagItems[i].debug());
        bagTable.add(stack).center().pad(0).padLeft(10).row();
    }
    // Add stack to table // size
    addActor(bagTable);

    // Set table position
    bagTable.setPosition(0, (Gdx.graphics.getHeight() / 2) - 200);
    bagTable.bottom().left();
}

enter image description here

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments