Thursday, July 21, 2022
HomeGame Developmentlibgdx - ButtonBuilder creates button that doesn't present up on display screen

libgdx – ButtonBuilder creates button that doesn’t present up on display screen


I needed to make a Button class for unit testing for a software program class. That is how the professor thought I ought to implement a button builder. Nonetheless when I attempt to run it, the static attracts happen however this button does not present up on the display screen. I am having the button lengthen Actor however am not sure if the explanation why is as a result of on this ButtonBuilder class, what’s being returned is a daily button as an alternative of a picture button.

package deal com.mygdx.recreation;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;

public class ButtonBuilder {

    public static Button createButton(String texturePath, float x, float y) {
        Button button = new Button(x,y);
        Texture texture = new Texture(Gdx.information.inside(texturePath));
        TextureRegion texRegion = new TextureRegion(texture);
        TextureRegionDrawable texDrawable = new TextureRegionDrawable(texRegion);
        ImageButton imgButton = new ImageButton(texDrawable);
        button.setRegionDrawable(texDrawable);
        button.setTexRegion(texRegion);
        button.setImgButton(imgButton);
        return button;
    }

stage = new Stage(new ScreenViewport());
        Gdx.enter.setInputProcessor(stage);
        Button newButton = ButtonBuilder.createButton(NEW_BUTTON_PATH, NEW_BUTTON_X, NEW_BUTTON_Y);
        stage.addActor(newButton);

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments