I have provided an aplication made in android that has a navigation drawer and in it has a list of games. I have to create another game and to put it there. The game that has to be created by my must use libGDX but the original application didn't use this library.
Is it possible to do this ? If Yes, how can I add the libgdx to the exiting project. On github I found only how to start a new project with libGDx, an not how to add it to exising code. thanks.
libGDX is a cross-platform Java game development framework based on OpenGL (ES) that works on Windows, Linux, macOS, Android, your browser and iOS.
You can achieve this with these 2 steps:
On your android gradle file: build.gradle (app or android module)
dependencies {
...
// Add this line, it is recommended to use the latest LibGDX version
api "com.badlogicgames.gdx:gdx-backend-android:1.9.10"
}
Option 1: Initialize for a view
Since you have a navigation drawer and more code native to android this option fits your needs better. From this question (How to add LibGDX as a sub view in android):
The AndroidApplication class (which extends activity) has a method named initializeForView(ApplicationListener, AndroidApplicationConfiguration) that will return a View you can add to your layout.
-- Matsemann
Also here's documentation on how to implement this (Fragment based LibGDX).
Option 2: Use a managed activity
This is the default/most common use of LibGDX, you will need to change your code as follows:
public class MainActivity extends AndroidApplication {
import com.badlogic.gdx.Game;
public class LibGDXGame extends Game {
@Override
public void create() {
System.out.println("Success!");
}
}
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
public class MainActivity extends AndroidApplication {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new LibGDXGame(), config);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With