Skip to content

Quickstart

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

In libgdx you would use ApplicationListener/ApplicationAdapter as entry-point. When using gdx-surface you should use BaseApplication instead. BaseApplication implements ApplicationListener and is the base of the screen feature (more on this later). Below is an a example implementation of BaseApplication and short examples of the usage of the core classes.

public class YourApp extends BaseApplication {

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

    @Override
    protected void init() {
        Gdx.input.setCatchBackKey(true);
        Gdx.app.setLogLevel(Application.LOG_NONE);
    }

    @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() {
        LoadingContent lc = new LoadingContent();
        Screen lcScreen = new SimpleScreen(viewport, lc);

        this.add(LOADING, lcScreen);

        return SquareScreens.LOADING;
    }

    @Override
    protected boolean isDebug() {
        return true; // true for debug-mode, false otherwise
    }

    @Override
    public void resize(int width, int height) {
        // ApplicationListener#resize(w, h)
    }

    @Override
    public void dispose() {
        // ApplicationListener#dispose()
    }

}
Clone this wiki locally