15
\$\begingroup\$

When I create a new LibGDX project the main class of Core project extends ApplicationAdapter. Here is how it looks like.

package com.marimba.apptest;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;

public class AppMain extends ApplicationAdapter {   
    @Override
    public void create () {

    }

    @Override
    public void render () {
        Gdx.gl.glClearColor(1, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    }
}

So I have to change the ApplicationAdapter to Game if I want to call setScreen method in order to switch between Screens. So what is the use of ApplicationAdapter ? When shall I use it ?

\$\endgroup\$

3 Answers 3

9
\$\begingroup\$

As @user3068350 said, both Game and ApplicationAdapter implement ApplicationListener. It's useful to extend Game if you plan on using the Screen interface in your game, however some developers may wish to take a different approach and handle screen management their own way. If this is the case, these will extend ApplicationAdapter.

Personally, I like my classes to implement a custom Updatable and/or Drawable interface, as I separate my render method into update and draw. In this case, using Screen would defeat the purpose as the interface contains a render method.

\$\endgroup\$
2
\$\begingroup\$

As the ApplicationAdapter and the Game class implement the ApplicationListener interface they can both be used almost interchangeably when creating your game. If you are set on using Screen, there is nothing stopping you from implementing them with both options.

The Game class has a little more overhead with it using Screens. However, this overhead is designed to make it easier to implement different stages/levels in your game. It is important to note that this overhead is minimal.

The ApplicationAdapter has no additional overhead (it is a straight implementation of an ApplicationListener). This gives you more control as you have to do everything yourself. Personally, I prefer to use ApplicationAdapters.

TL;DR: No real difference between them. ApplicationAdapter gives you a little more control & Game is a little less work.

\$\endgroup\$
1
\$\begingroup\$

The Game class implements the ApplicationListener interface and is just a class that is designed to make it easy to switch between different screens. When a method in the ApplicationListener is called, the Game class takes care of delegating it to the currently set screen.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ but when should I use ApplicationAdapter? And how shall I use screens here. \$\endgroup\$ Commented Jul 4, 2015 at 13:57
  • 2
    \$\begingroup\$ You dont need to use ApplicationAdapter. Both ApplicationAdapter and Game implements the ApplicationListener interface. An adapter class is just a class that provides skeleton implementations for an interface so you dont have to clutter your code with empty method bodies. To use screens with Game you call setScreen and pass in a class that implements the Screen interface. You can make your screen classes take a Game object in the constructor so you can change screens within a screen. \$\endgroup\$ Commented Jul 4, 2015 at 14:14
  • 1
    \$\begingroup\$ so why they have created ApplicationAdapter if it doesn`t have any use? \$\endgroup\$ Commented Jul 4, 2015 at 14:52
  • 2
    \$\begingroup\$ @VaheMuradyan, user already answered that: you don't have to clutter your code with empty method bodies. When you implement ApplicationListener directly, you have to provide all of the required methods, including ones that you don't need (like pause() or resume(), which aren't always used). ApplicationAdapter is out there for your convenience, so you don't have to keep empty methods around. It's a simple utility class, it adds no new functionalities - it just keeps your code cleaner (or shorter). \$\endgroup\$
    – Czyzby
    Commented May 3, 2016 at 13:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .