Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

How does super.render() call this method?

$
0
0

Today I was experimenting with adding different screens with Scene2d in libgdx and while doing so I became confused how super.render() in my render() method from my starter class (MyGdxGame) called render() in my PlayScreen() class. Basically I understand you use super to call methods, fields, invoke a super class constructor etc… however I don’t see how my Main class witch extends Game is a subclass/derived class of my PlayScreen class witch simply implements Screen. In short I don’t see how those two classes are related so that super.render() in MyGdxGame class can call render() in my PlayScreen class.

Also I looked at the API and Screen implements ScreenAdapter and Game implements ApplicationListener but I still don’t see how that connects.

Starter class:

public class MyGdxGame extends Game {
    Game game;

    @Override
    public void create() {
        game = this;
        setScreen(new MainMenu(game));
    }

    @Override
    public void render() {
        super.render();
    }

    public void dispose() {
        super.dispose();
    }

    public void pause() {
        super.pause();
    }
}

PlayScreen class:

public class PlayScreen implements Screen {
    private static Player player;
    SpriteBatch batch;
    GameControls x;
    CollisionManager collisionManager;
    ArrayList<Tree> trees;
    Iterator itr;
    Enemy enemy;
    Animations animation;
    Game game;
    MainMenu mainMenu;

    public PlayScreen(Game game, MainMenu mainMenu) {
        this.game = game;
        this.mainMenu = mainMenu;
    }
// more code ...
}

Viewing all articles
Browse latest Browse all 434

Trending Articles