0
\$\begingroup\$

I have a Group object comprised of 2 actor members. Each member in the group can have their height, width, and positions scaled and set independently with no issues. However, attempting to utilize setRotation() or rotateBy() on an individual member of the group does not cause the member to rotate. The entire group can be rotated at once, but not an individual member in the group. Is there a way to rotate a single actor member that is part of a group?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

I was trying to do a similar thing with a Label in my case. Setting the rotation on the Label didn't seem to behave as expected, so I ended up wrapping it in a Table.

A table may have been a bit overkill as a Container may have been sufficient. Here's what I did (I've trimmed it down to just the important parts, so this is untested code -- but it should convey what I did):

public class RotatedLabel extends Table {
    public RotatedLabel(String labelText, Skin skin) {
        super();
        innerLabel = new Label(labelText, skin);
        innerLabel.setOrigin(Align.center);
        innerLabel.setAlignment(Align.center);


        setTransform(true);
        setFillParent(false);
        add(innerLabel);
    }
    .
    .
    .
}

I am able to create the labels with minimal effort by just instantiating it with new RotatedLabel("Hello World", skin);

Keep in mind that the rotation is around the Table's origin (in this case). My label has more custom code in the act(float delta) method that sets the rotation and I update the origin and rotation in that function:

@Override
public void act(float delta) {
    super.act(delta);
    .
    .
    .
    setOrigin(getWidth() / 2, getHeight() / 2);
    setRotation(rotation);
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .