I want to create a floating help bubble to introduce the basic functioning of my game. This bubble should float above the Actor I want it to explain, like shown in the picture below.
To accomplish this, I want the coordinates of the Actor, in this case the left button, and then I can add the bubble Actor to the Stage in front of everything else. The last part is easy enough, but I'm struggling with retrieving the actual coordinates of the button, as it is in a table.
The two buttons are added to a Table like this:
t.add(btnLab).expandX().center();
t.add(btnSea).expandX().center();
I've tried the most obvious approach:
Vector2 loc = new Vector2(a.getX(), a.getY());
System.out.println("Loc: " + loc);
a.localToStageCoordinates(loc);
System.out.println("Loc: " + loc);
This gives me (in the order of the sysouts): [0.0, 0.0] and [40.0, 130.0]. The last position is actually the position of the Table, which fills the blue area of the screen. So this location obviously misses something the Table does to place the Actor, and cannot be used (as I only end up with the location of the Table).
(I've also tried using t.localToStageCoordinates here, t being the Table. Same results.)
Another solution I tried was to recursively search through all Parents:
private static Vector2 getLoc(Actor a) {
return getLoc(new Vector2(a.getX(), a.getY()), a.getParent());
}
private static Vector2 getLoc(Vector2 loc, Actor g) {
System.out.println("Location: " + loc + ", Actor: " + g);
loc.x += g.getX();
loc.y += g.getY();
if(g.getParent() == null) return loc;
return getLoc(loc, g.getParent());
}
Unfortunately, this gives me the same. The sysouts gives the following:
Location: [0.0:0.0], Actor: Table 40.0,130.0 944.0x508.0
Location: [40.0:130.0], Actor: Group 0.0,0.0 0.0x0.0
Location: [40.0:130.0], Actor: Group 0.0,0.0 0.0x0.0
So I can't seem to get the actual positions of the Groups/Actors within the Table.
How am I supposed to do this?