Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit) (+1)

I'm glad to announce that the codename for the FastTeam's entry is SpaceFloat and it will be a game about a delivery service in the space!

I'm going to continue these devlogs writing about some practices I use with libGDX. So, here is a devlog about the SpaceFloat screen management.

SpaceFloat Screen Management

You could see a better formatted version of this devlog at this link.

SpaceFloat is divided in well-defined screens encapsulated in the ScreenEnumerator, so it's very simple to retrieve a singleton of a screen: ScreenEnumerator.INFO.getScreen();.

public enum ScreenEnumerator {
    INFO(new InfoScreen()),
    MAIN(new MainScreen()),
    LOADING(new LoadingScreen());

    private SpaceFloatScreen screen;

    ScreenEnumerator(SpaceFloatScreen screen) {
        this.screen = screen;
    }

    public SpaceFloatScreen getScreen() {
        return screen;
    }
}

The SpaceFloatGame class, subclass of Game, is responsible of the application life-cycle, including the current screen. A screen is initialized within the method setScreen(ScreenEnumerator) which, if the screen is not yet initialized, will invoke injectDependencies(SpaceFloatScreen) to inject all required dependencies.

public void setScreen(ScreenEnumerator screenEnumerator) {
    SpaceFloatScreen screen = screenEnumerator.getScreen();
    if (!screen.isInitialized()) injectDependencies(screen);
    setScreen(screen);
}

private void injectDependencies(SpaceFloatScreen screen) {
    screen.setAssetManager(assetManager);
    screen.setFont(font);
    screen.setEngine(engine);
    screen.setGame(this);
    screen.setInitialized(true);
}