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!