Vswe's Summer Courses | You're not logged in. Sign up or log in | Server time: | Donate
One can now see other persons' badge hunts. Simply head over to their profiles to access them.

Go back to lecture page

Climbing the interface ladder

From basic graphical interfaces to very advanced ones

2. Basic Interfaces

Offcentered button

  • 2013-08-10 17:15:29
    I created a button in the GUI over a progress bar using this code:
    buttonList.add(new GuiButton(0, guiLeft + 117, guiTop + 19, 50, 20, "New cake"));
    And when I opened Minecraft I noticed it was off-centered because it needed one more pixel on the right. So I tried:
    buttonList.add(new GuiButton(0, guiLeft + 117, guiTop + 19, 51, 20, "New cake"));
    But I got the exact same result. I tried:
    buttonList.add(new GuiButton(0, guiLeft + 117, guiTop + 19, 52, 20, "New cake"));
    and it was still off centered but this time it had one pixel more.
    I took a screenshot of the button with 51 width and I noticed that the actual width was 50 pixel and not 51. Why? D:

    pic: https://dl.dropboxusercontent.com/u/70978256/2013-08-10_19.06.04.png (I've added some lines to the texture with paint to count the pixels better)
  • 2013-08-10 17:31:35
    Well, you're only changing its width, you'll have to move it one pixel to the left. Decrease its x position by 1 by changing "guiLeft + 117" to "guiLeft + 116".
  • 2013-08-10 17:43:04
    That's not the problem. The button is 50 wide, the progress bar is 47. The button has two pixels to the left of the bar and one to right.
    51 wide -> the button is still 2 pixels to the left and one to the right
    52 wide -> the button is 2 pixel to the left and three to the right
  • 2013-08-10 18:28:23
    I just took a look in the code of the GuiButton. You can't have widths which are odd numbers. The reason is because it splits the button in two halves so it can render the left and the right edge properly (i.e. The button can have a dynamic width but can still use the same texture).
  • 2013-08-10 18:33:21
    Oh that's why! Thanks
  • Log in or sign up to reply to this thread