LibGDX - Drop down menu?

Hi guys, I was just wondering if this is the correct way of going about a drop down menu.

I was thinking of creating a bar along the top of my game that when the user touches it, I use actions to move it down onto the screen/back off the screen. Just not sure if this is the correct way of doing it :point:

Thanks!

Why don’t you use Scene2D? Specifically, you might try using a SelectBox.

You might also try googling “libGDX drop down menu”, which returns results like this.

I tried :frowning: everyone seems to want to use the select box but i’m not sure if that fits my needs. The select box shows a default value correct? Though I’d want the drop down to have a title and then widgets under that

One of the neat things about programming is that you can extend existing components to change their behavior.

The first option that occurs to me is that the drop-down menu’s title might be the default value of the SelectBox.

I recommend trying something out and putting together a small example program if you can’t get it working.

Meh, the way I would do it just because I’m lazy is just have a Drop down menu class. In there I would have the position that I want it to be in when it retracts (OriginPosX, OriginPosY), and then the position that it will be in when it shows up (EndPosX, EndPosY) . I would also have some more variables that keep track of the menu’s current position (x, y) and it’s width and height.
It would end up looking something like this. Sorry if syntax is wrong I’m writing the code straight from the browser:

 

   public class DropDownMenu{

             private int OriginPosX, OriginPosY, EndPosX, EndPosY, Width, Height, x, y, Speed;
             private boolean isHovered, isVertical;
            
             public DropDownMenu(int OriginPosX, int OriginPosY, int Width, int Height, int Speed, boolean isVertical){
                     this.isVertical = isVertical;
                     this.OriginPosX = OriginPosX;
                     this.OriginPosY = OriginPosY;
                     this.Width = Width;
                     this.Height = Height;

                if(isVertical == false){
                     this.EndPosX = OriginPosX + Width;
                     this.EndPosY = OriginPosY;
                  }
 
                if(isVertical == true){
                     this.EndPosY = OriginPosY + Height;
                     this.EndPosX = OriginPosX;
                  }
                     this.x = OriginPosX;
                     this.y = OriginPosY;
                     
     }

            public void update(){
                  if(MousePosX > x && MousePosX < x+Width && MousePosY > y && MousePosY < y + Height){
                           isHovered = true;

                        }
                   else{
                           isHovered = false;
                    }

                 if(isHovered == true){
                         if(x < EndPosX){
                               x += Speed;
                         }
                         if(y < EndPosY){
                               y += Speed;
                        }
                   }

                  else{
                        if(x > OriginPosX){
                             x -= Speed;
                          }
                        if(y > OriginPosY){
                             y -= Speed;
                         }
                   }
                   
           }

           public int getX(){
                      return x;
                }
           public int getY(){
                      return y;
          }
}


Then you would create an instance of this Drop down menu class for each menu you want and move your buttons according to the Menu’s x and y position, So (example) :


DropDownMenu ddm = new DropDownMenu(100, 100, 20, 20, true );

     public void yourUpdateMethodthatContinuouslyLoops(){
            yourButton.x = ddm.getX()+The offset you want;
            yourButton.y == ddm.getY()+The offset you want;
  
       }

So hopefully this code works (didn’t check), and hopefully it proves useful. I’m very much a noob but I try my best to help. This code should also hopefully work in Drop down menus and Drop (side?) Menus!