Feature request: An event in ManagedScreen that is called each time a transition ends, on both involved screens
Let's say I want to show the same screen again, but I want to reinitialize it. (Restart the same level for example).
Hey @dkoding, thanks for the suggestion! I'll have to think about how to properly implement this, so it is in line with the currently existing screen events. It might even make sense to remove show(), hide(), pause(), resume(), resize(x, y) and just use an event bus instead.
Back to your problem: Something similiar can already be achieved by ManagedScreen#show() and hide(). However, show() is already called at the start of the transition and hide() is only called on the screen that is no longer visible, see here.
If you want to implement this feature yourself, you can also use a custom version of the default screen manager:
public class MyGdxGame extends ManagedGame<MyScreen, ScreenTransition> {
@Override
public final void create() {
this.screenManager = new MyScreenManager();
super.create();
// ...
}
}
And then in MyScreenManager, you can call any method you want of your MyScreen, e.g. onTransitionFinished(); the section you'd need to change is located here.
Thanks for your reply. You could consider opening up the ScreenManager a little, refactor code bits into protected overridable methods.
For now, I've scrapped the idea of introducing an event-based approach, but the recently released version 0.7.0 opens up ScreenManager even more. If anyone wants to extend screenmanager in such a way as suggested here, they should check out #initializeScreen, #initializeTransition, #finalizeScreen, and #finalizeTransition.