Search code examples
javarotationlibgdxcoordinate-transformation

LibGdx How to get total stage rotation for child of group?


Similar to this question: https://stackoverflow.com/a/23701065

But I was wondering if there is a way to get the current rotation for the child of a group instead of the position?

For example:

Group g1 = new Group();
Group g2 = new Group();
Actor a = new Actor();
g1.addActor(g2);
g2.addActor(a);
g1.setRotation(90);
g2.setRotation(45);
//How to get `a` actual rotation in reference to stage?

Solution

  • To expand on @noone's comment and put what I ended up with:

    I have already extended Group with my own subclass, so I just added the following method:

    /**
     * Returns the total rotation of the parent grouping.
     * Does not include this group's rotation.
     **/
    public float getTotalParentRotation()
    {
        Group g = this.getParent();
        float rotation = 0.00f;
        while (g!=null) {
            rotation += g.getRotation();
            g = g.getParent();
        }
        return rotation;
    }