Search code examples
javabuttonlibgdxscene2d

libGDX, Scene2d Button status


Hello I have some questions for adding images for a ImageButton.

I have an icon for example a play button now if I hover over the button it just should get a blue surounding box the inside Image should not change.

  1. Should I draw for every icon the two states or are there other options.

  2. If an button is not clickable it should get Grey. Same how to do this? Add an additional Image to every Icon?

  3. For what is the Checked drawable in the ImageButton?


Solution

    1. ImageButtons have a drawable for their background (up, down, over, etc.) and a drawable for the image on top of the button (imageUp, imageDown, imageOver, etc.). The only ones you must provide are up for the background and imageUp for the icon. These are the defaults used when you leave the other states null. But for visual reasons, you need down for the background or it will be hard to tell if the button is being pressed. It's up to you whether you think you need to also change the icon appearance with an imageDown.

    2. All you need is to add the background drawable for disabled. If you want the icon to also turn gray, you need to create a gray version of the icon and assign it to imageDisabled.

    3. The Buttons in Scene2d all support toggle functionality. When you press it, it will toggle to the checked state, so you can use the checked drawable to change its appearance while it is stuck down. If you don't want that to happen, leave the checked drawable null.