-
Notifications
You must be signed in to change notification settings - Fork 0
Manual project setup
Note: Java 1.7 currently causes problems with Android. Please make sure your project uses Java 1.6 Note: use of setup-ui is highly recommended if you want to deploy to iOS
This page describes how to configure Eclipse to develop and run libgdx applications on both the desktop and Android.
- Create a new Java project in Eclipse: File -> New -> Project -> Java Project. Give it a name and click Finish.
- Go to the project folder on the file system and create a sub-folder named
libs
. Download thelibgdx-nightly-latest.zip
and placegdx.jar
andgdx-sources.jar
in the libs folder. - In Eclipse, right click the project -> Refresh. Right click again -> Properties -> Java Build Path -> Libraries -> Add JARs, select
gdx.jar
and click OK. - Under the
gdx.jar
file, double click "Source attachment", click Workspace, select thegdx-sources.jar
and click OK. - Click the Order and Export tab, check the
gdx.jar
and click OK.
Note: Step 5 makes gdx.jar
a transitive dependency. That means that projects that depend on the main project will also have gdx.jar
on their classpath. However, this doesn't work for Android projects.
- Create a new Java project in Eclipse: File -> New -> Project -> Java Project. Name it appropriately (eg, "gamename-desktop") and click Finish.
- Go to the project folder on the file system and create a sub-folder named
libs
. From thelibgdx-nightly-latest.zip
, placegdx-natives.jar
,gdx-backend-lwjgl.jar
andgdx-backend-lwjgl-natives.jar
in the libs folder. - In Eclipse, right click the project -> Refresh. Right click again -> Properties -> Java Build Path -> Libraries -> Add JARs, select the three JARs and click OK.
- Click the Projects tab, click Add, check the main project and click OK.
Before doing these steps, the Android SDK must first be installed.
- Create a new Android project in Eclipse: File -> New -> Project -> Android Project. Name it appropriately (eg, "gamename-android"). For build target, check "Android 1.5". Specify a package name (eg, "com.gamename"). Next to "Create Activity" enter "AndroidGame". Click Finish.
- Go to the project folder on the file system and create a subfolder named
libs
. From the nightly zip, placegdx-backend-android.jar
and thearmeabi
andarmeabi-v7a
folders in the libs folder. - In Eclipse, right click the project -> Refresh. Right click again -> Properties -> Java Build Path -> Libraries -> Add JARs, select
gdx-backend-android.jar
and click OK. - Click Add JARs again, select
gdx.jar
under the main project and click OK. - Click the Projects tab, click Add, check the main project and click OK twice.
- Click the Order and Export tab, check the main project.
Note: The folder really must be called "libs", a naming convention forced on us by the Android Eclipse plugin.
The Android project has a sub-folder named assets
, which is created automatically. Files available to the Android application must be placed here. This is problematic, because these same files must be available to the desktop application. Rather than maintain two copies of all the files, the desktop project should be configured to find the assets in the Android project:
- Click the Source tab, click Link Source, Browse, select the "assets" folder from your Android project and click OK.
- Specify "assets" for the folder name and click Finish then OK.
Note: If your desktop and Android projects are in the same parent folder, you can use "PARENT-1-PROJECT_LOC/gamename-android/assets
" for the location of the linked assets folder, where "gamename-android
" is the name of your Android project. This is better than a hard-coded path if you plan on sharing your projects with others.
In your main project, create a new class: right click the project -> New -> Class. Name it "Game" and specify a package (eg, "com.gamename"). Next to Interfaces, click Add, choose ApplicationListener
, and click OK. It will look like this:
import com.badlogic.gdx.ApplicationListener;
public class Game implements ApplicationListener {
public void create () {
}
public void render () {
}
public void resize (int width, int height) {
}
public void pause () {
}
public void resume () {
}
public void dispose () {
}
}
These methods allow you to setup and render your game. Since they are empty, this particular game is simply a blank screen. We will first get this simple game running before doing something more interesting.
Right click the desktop project -> New -> Class. Name it DesktopGame
and specify a package (eg, "com.gamename"). Click OK. Make the class look like this:
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
public class DesktopGame {
public static void main (String[] args) {
new LwjglApplication(new Game(), "Game", 480, 320, false);
}
}
This code creates an LwjglApplication, gives it an instance of your game, a title, and size. The "false" means we aren't using OpenGL ES 2.0 (we will use 1.0/1.1).
To run the game on the desktop, right click the project -> Debug As -> Java Application. You should get a black window titled "Game".
Open the AndroidGame
class in the Android project that was automatically created and make it look like this:
import com.badlogic.gdx.backends.android.AndroidApplication;
public class AndroidGame extends AndroidApplication {
public void onCreate (android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initialize(new Game(), false);
}
}
This code is an Android activity that calls initialize, passing an instance of your game. Again, the "false" means we aren't using OpenGL ES 2.0.
To run the game on Android, right click the project -> Debug As -> Android Application. The screen will turn black, since the game doesn't yet do anything. If any errors occur running the application, they show up in the Logcat view, which can be seen by clicking Window -> Show View -> Other -> Android -> Logcat.
At some point you may want to update libgdx to the latest. To do this, download the libgdx-nightly-latest.zip
again and update these files in your projects:
Project | Files |
---|---|
main | libs/gdx.jar libs/gdx-sources.jar |
Android | libs/gdx-backend-android.jar libs/armeabi (directory) libs/armeabi-v7a (directory) |
desktop | libs/gdx-natives.jar libs/gdx-backend-lwjgl.jar libs/gdx-backend-lwjgl-natives.jar |
-
Developer's Guide
- Introduction
- Goals & Features
- Community & Support
- Contributing
- Games Built with Libgdx
- Prerequisites
- Gradle Project Setup, Running, Debugging and Packaging
- Project Setup, Running & Debugging
- Third Party Services
- Working from Source
- Using libgdx with other JVM languages
- The Application Framework
- A Simple Game
- File Handling
- Networking
- Preferences
- Input Handling
- Memory Management
- Audio
-
Graphics
- Configuration & Querying Graphics ??
- Fullscreen & VSync
- Continuous & Non-Continuous Rendering
- Clearing the Screen
- Take a Screenshot
- OpenGL ES Support * Configuration & Querying OpenGL ?? * Direct Access ?? * Utility Classes * Rendering Shapes * Textures & TextureRegions * Meshes * Shaders * Frame Buffer Objects
- 2D Graphics * SpriteBatch, TextureRegions, and Sprite * 2D Animation * Clipping, with the use of ScissorStack * Orthographic camera * Mapping Touch Coordinates ?? * Viewports * NinePatches * Bitmap Fonts * Distance field fonts * Using TextureAtlases * Pixmaps * Packing Atlases Offline * Packing Atlases at Runtime * 2D Particle Effects * Tile Maps * scene2d * scene2d.ui * Skin
- 3D Graphics * Quick Start * Models * Material and environment * 3D animations and skinning * Importing Blender models in LibGDX * Perspective Camera ?? * Picking ??
- Managing Your Assets
- Utilities
-
Math Utilities
- Interpolation
- Vectors, Matrices, Quaternions
- Circles, Planes, Rays, etc.
- Path interface & Splines
- Bounding Volumes ??
- Intersection & Overlap Testing ??
- Physics
- Tools
- Extensions
- Deploying your Application
- Building Libgdx ??
- Known Issues
- Articles
- Deprecated (May be outdated)