Skip to content

BaseApplication

Rico Schrage edited this page May 9, 2017 · 5 revisions

The BaseApplication is the entry-point of the framework. Every game should have a class extending it. Basically it's an implementation of libgdx's ApplicationListener. Here is a minimal example:

public class YourApp extends BaseApplication {

    @Override
    protected Viewport createViewport() {
        return new ScreenViewport();
    }

    @Override
    protected void loadResources(ResourceHandler resourceHandler) {
        resourceHandler.loadResource(YourResourceEnum.values());
    }

    @Override
    protected ScreenId createScreens() {
        UserInterface ui = new UserInterface();
        GameContent game = new GameContent();

        Screen uiScreen = new SimpleScreen(viewport, ui);
        Screen gameScreen = new SimpleScreen(viewport, game);

        this.add(UI, uiScreen);
        this.add(GAME, gameScreen);

        return UI;
    }

    @Override
    protected ScreenId createLoadingScreen() {
        Content loadingContent = new LoadingContent();
        Screen screen = new SimpleScreen(viewport, loadingContent);

        add(LOADING_SCREEN, screen);

        return LOADING_SCREEN;
    }
}

In the following section we will explain the important methods of BaseApplication:

  • (createViewport) In this method you can create the viewport of your game. This viewport will automatically applied and passed to your contents, you don't really have to deal with it after creating it.
  • (loadResources) Here you should load your resources with your ResourceHandler. We will describe the ResourceHandler at a later point.
  • (createScreens) At this point you can create your screens and contents (for further information look at the screen/content section). The return value of this method determines the start-screen.
  • (createLoadingScreen) Here you can create the loading screen analogous to createScreens().
  • (add) After creating a screen you can add it with this method to the app.
  • (isDebug) If it returns true the fps will be drawn on the screen.
  • (resize/resume/pause/dispose) Analogous to the libgdx methods (life-cycle).
Clone this wiki locally