UbuLin

2D Why is the input of my button moved[LibGDX]?

Recommended Posts

Hello everybody,
I've been a bloody problem for a few days now.
I created a button in LibGDX. This button I have packed on a table and the table I have packed on a stack and the stack again to a stage.
The problem is that I have to push a few pixels next to the button in order to erase.
That means when I press exactly on the button nothing happens.

I will copy here the times the appropriate code slightly shortened.
I could also shorten the code a bit.

public class HUD implements Disposable {
    PlayScreen screen;

    public static Stage stage;
    private Viewport viewport;

    private Stack stack;

    public HUD(PlayScreen screen, SpriteBatch sb) {
        this.screen = screen;

        viewport = new FitViewport(PlayScreen.V_WIDTH, PlayScreen.V_HEIGHT, new OrthographicCamera());
        stage = new Stage(viewport, sb);

        stack = new Stack(); // This is the Stack
        stack.setFillParent(true);
        stack.addActor(buildHudLayer()); // Here I add another Table to the Stack
        stack.addActor(buildButtonLayer()); // Here I add the Table with the Button to the Stack
        stage.addActor(stack); // Here I add the Stack to the Stage
        PlayScreen.multiplexer.addProcessor(stage); // Here I add the input of the Stage to an InputMultiplexer
        screen.setInput();
    }

    private Label fpsLabel;
    private Label levelLabel;

    private Table buildHudLayer() { // This is another table
        Table table = new Table();
        table.top();

        fpsLabel = new Label(Gdx.graphics.getFramesPerSecond() + "fps", new Label.LabelStyle(new BitmapFont(), Color.BLACK));
        levelLabel = new Label(Masterrunner.currentLevel + " - " + Masterrunner.currentLevel, new Label.LabelStyle(new BitmapFont(), Color.BLACK));

        table.add(fpsLabel).expandX();
        table.add(levelLabel).expandX();

        return table;
    }

    private Table buildButtonLayer() {
        Table table = new Table(); // Here I create the table
        table.setFillParent(true);
        table.setDebug(true);
        table.top();

        Button.ButtonStyle style = new Button.ButtonStyle(); // This is the Button
        style.up = new TextureRegionDrawable(PlayScreen.atlas.findRegion("Pause"));
        style.down = new TextureRegionDrawable(PlayScreen.atlas.findRegion("Pause1"));
        Button pauseButton = new Button(style);
        table.add(pauseButton).size(20, 20); // Here I add the Button to the Table

        return table; // Here I return the Table
    }

    public void update() {
        fpsLabel.setText(Gdx.graphics.getFramesPerSecond() + "fps");
        levelLabel.setText(Masterrunner.currentWorld.getName() + " - " + Masterrunner.currentLevel);
        stage.act();
	}

    public void render() {
        stage.draw();
    }
}

I hope the information is sufficient, if not corrected me please.

 

Dear greetings UbuLin ;D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Forum Statistics

    • Total Topics
      628293
    • Total Posts
      2981869
  • Similar Content

    • By muhamad rabee
      My first mobile game made by unity

      iphone: https://itunes.apple.com/us/app/aa-countdown/id1314223584?ls=1&mt=8

      android: https://play.google.com/store/apps/details?id=com.mr.AACountDown

      I appreciate every suggestion
    • By Simplepg
      https://play.google.com/store/apps/details?id=simple.gplay.GamesInABox
    • By Simplepg
      https://play.google.com/store/apps/details?id=simple.gplay.GamesInABox
    • By ForgedInteractive


      Who We Are
      We are Forged Interactive, a small team of like-minded game developers with the sole purpose of making games we love! We're a team of artists, animators, programmers, level designers, writers, composers, producers, and other creative minds. We want to make games that you, the modern gamer want to play! We hope to build a community that enjoys our games as much as we love creating them. With your feedback and support we will be able to achieve that.

      About the Game
      GAME NAME is a fun, action-packed army builder with unique characters, challenges and engaging levels. Set forth on an adventure to protect friends, family and countrymen from new adversaries. Once defeated your enemies turn coat and join you in your adventures. Players can enjoy a range of troops and abilities based on their gameplay style which become more important as maps introduce more challenging terrain, enemies and bosses. Strong orc knights, dangerous shamans, and even a dragon are out on the prowl. Knowing when to fight and when to run, and how to manage your army is essential. Your actions alone decide the fate of this world.

      Previous Work by Team
      Although we are working towards our first game as a team, our team members themselves have past experience in the industry.
      This includes members who have worked on titles including:
      Final Fantasy Kingsglaive, FIFA, Xcom 2 and Civilization.

      Who are we looking for? 3D Modellers Concept Artists Marketing Specialists Level Designer

      What do we expect? Reference work or portfolio. Examples what have you already done and what projects you have worked on academic or otherwise. The ability to commit to the project on a regular basis. If you are going on a two-week trip, we don't mind, but it would be good if you could commit 10+ hours to the project each week. Willingness to work with a royalty based compensation model, you will be paid when the game launches. Openness to learning new tools and techniques
      What can we offer? Continuous support and availability from our side. You have the ability to give design input, and creative say in the development of the game. Shown in credits on websites, in-game and more. Insight and contacts from within the Industry.
      Contact
      If you are interested in knowing more or joining. Please email or PM us on Skype. Myself or Colin will reply to you within 48 hours.

      E-mail: Recruitment@ForgedInteractive.com
      Skype: ForgedInteractive

      Regards,
      David and Colin

      Follow us on:

      Facebook: https://www.facebook.com/ForgedInteractive/
      Twitter: @ForgedInteract
      Youtube: https://www.youtube.com/channel/UCpK..._as=subscriber
      Reddit: https://www.reddit.com/user/Forged_Interactive/
    • By Brian Paek
      Football Dash now on iOS! Over 1 million downloads on Android
      iOS:
      https://itunes.apple.com/us/app/football-dash-endless-runner/id1312590451?ls=1&mt=8
      Android:
      https://play.google.com/store/apps/details?id=com.beastattack.c1434846484727

  • Popular Now