Jump to content

Recommended Posts

Posted

I know how to add click-able buttons, but how do you change the texture of buttons in a GUI?

 

heres a gui class that adds some buttons that have custom widths

 

  Reveal hidden contents

 

Posted
  On 4/2/2015 at 11:47 PM, diesieben07 said:

You need a class that extends GuiScreen, then you can override the draw method in there.

 

You mean GuiButton, right?

 

He is already extending GuiScreen, but the drawScreen() method there actually usually isn't used for the buttons since they have their own drawButton() method that is called automatically if the button is in the GuiScreen's button list.

 

Here is an example of the method from one of my mods.:

      /**

        * Draws this button to the screen.

        */

        @Override

        public void drawButton(Minecraft mc, int parX, int parY)

        {

            if (visible)

            {

                boolean isButtonPressed = (parX >= xPosition

                      && parY >= yPosition

                      && parX < xPosition + width

                      && parY < yPosition + height);

                GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

                mc.getTextureManager().bindTexture(bookPageTextures[1]);

                int textureX = 0;

                int textureY = 192;

 

                if (isButtonPressed)

                {

                    textureX += 23;

                }

 

                if (!isNextButton)

                {

                    textureY += 13;

                }

 

                drawTexturedModalRect(xPosition, yPosition,

                      textureX, textureY,

                      23, 13);

            }

        }

    }

 

The key is the drawTexturedModalRect() method which is taking part of a texture.  In this case I take a different part of the texture based on whether the button is pressed or not.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

  Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

  Your link has been automatically embedded.   Display as a link instead

  Your previous content has been restored.   Clear editor

  You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Create New...

Important Information

By using this site, you agree to our Terms of Use.