Search code examples
javaandroidlibgdxresizeactor

Is there a Listener for when an actor gets resized?


I was wondering if there is an easier way to execute a specific method on a resize than what I have written in the code snippet below.

@Override
    public void resize(int width, int height) {
        stage.getViewport().update(width, height, true);
        for (Table t : tabPane.tabs) {
            resize(stage.getViewport().getWorldWidth(), t);
        }
    }


private void resize(float width, Group group) {
        SnapshotArray<Actor> children = group.getChildren();
        Actor[] arr = children.begin();
        for (Actor a : arr) {
            if (a instanceof SoundButton) {
                ((SoundButton) a).resized(width);
            } else if (a instanceof Group) {
                resize(width, (Group) a);
            }
        }
        children.end();
    }

Thanks in advance.


Solution

  • The Actor class has a method which you can override called sizeChanged

    @Override
    public void sizeChanged() {
       // Add Your code here
    }