Reputation: 882
When you start a project with libgdx it automatically makes the class extend Android Application. I did not think about this until later and now I want to change it to the Game and Screen classes. But unfortunately without success...
My first question is, how to I change the android project?
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
public class AndroidClass extends AndroidApplication {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = false;
initialize(new SplashScreen(), cfg);
}
}
My second question: How do I change the deskop project:
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
public class DeskopClass {
public static void main(String[] args) {
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "MyApp";
cfg.useGL20 = false;
cfg.width = 800;
cfg.height = 480;
new LwjglApplication(new SplashScreen(), cfg);
}
}
Third question: How do I change the SplashScreen:
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class SplashScreen implements ApplicationListener{
@Override
public void create() {
// TODO Auto-generated method stub
}
Thanks!
Upvotes: 0
Views: 855
Reputation: 7057
Game class in libgdx is itself an ApplicationListener.
You can create a class that extends Game and directly pass its object to initialize (for android) and LwjglApplication (for desktop). This way you can use setScreen without a problem.
Upvotes: 0
Reputation: 12745
The Game class is just an ApplicationListener
. AndroidApplication
and Game
are not interchangeable classes as they accomplish two different things.
You need an AndroidApplication
class to pass events on to your ApplicationListener
classes. If you want a Game
class in your app then you can always create your own.
public class Game implements ApplicationListener {
@Override
public void dispose () {
}
@Override
public void pause () {
}
@Override
public void resume () {
}
@Override
public void render () {
}
@Override
public void resize (int width, int height) {
}
}
Upvotes: 3