• Sponsored Links

Step by Step Tutorial on libGDX

Share this :

Full Tutorial Seris on libGDX

LibGDX is a Java based game library capable of targeting iOS, Android, Desktop ( Windows, Mac and Linux ) and HTML5 which means you code only once but can run and deploy it on iOS, Android, Desktop ( Windows, Mac and Linux ) and HTML5.

It provides a full suite of 2D game functionality including Input, Graphics, Fonts, Physics, Storage and increasingly, 3D. So basically LibGDX is pretty much a one stop game development library.

libGDX

Recently I was looking for a game development framework using Java and after reading a lot of blogs and some research I came to a conclusion to learn libGDX .

To deploy and run a minimal hello world program to get some confidence on the tool and to understand how easy and good this framework is , I started reading tutorials from

  1. http://www.gamefromscratch.com
  2. https://github.com/

http://www.gamefromscratch.com  is really good but due to a lot of updates in libGDX and other tools my minimal sample application kept on failing and hence i moved to git hub wiki to learn more on how to deploy Demo run. I failed several times there as well , so thought of write this step by step procedure on libGDX . Again , big thanks to both  http://www.gamefromscratch.com and https://github.com/libgdx/libgdx/wiki


 

Java JDK : Download and install latest Java JDK . I am using Java jdk1.8.0_31 . Once Java is installed , Check it by opening command prompt and executing command java -version

JavaVersion

 

Eclipse : The “Eclipse IDE for Java Developers” is usually sufficient. I downloaded Eslipse 64 bit Mars using following Link

Android SDK : Android SDK can be installed using following link : Android SDK  . Currently Android SDK is supported by IntelliJ IDE so the way i preferred to download Android SDK was to get from Eclipse directly as below :

  • Start Eclipse, then select Help > Install New Software.
  • Click Add, in the top-right corner.
  • In the Add Repository dialog that appears, enter “ADT Plugin” for the Name and the following URL for the Location: https://dl-ssl.google.com/android/eclipse/
  • Click OK and Eclipse will download the android SDK for you .
  • Once Downloaded make sure you know the path of the android sdk . for me it was downloaded in C:\Users\<USER>\android-sdks
  • We will need this path later on …

EclipseAndroidTools

Google ADT and Google Plugin for Eclipse ( for GWT ) : For this I used Eclipse Integration Gradle, use this update site:

 

EclipseGradle

In Case you face issues in installation , Please add your comments or look at libGDX github wiki page for their instructions on setting up Development environment here

 

libGDX : Open libGDX download page using following link : libGDX and click Download Setup App . Doing that you will see a file named gdx-setup.jar downloaded which is the main setup app for libGDX projects .It is Gradle based setup application which will download all that’s required automatically!

Once all this is done … We can say most setup are done and we are ready to execute the demo app provided by libGDX .



 

  •  Creating Project in libGDX via gdx-setup.jar

    Double click gdx-setup.jar and you will see a gui as below :

libGDX_defaultGUI

 

Change Name to any good name you like , I am using versionpb

Change Package to any package name you like , I am using com.versionpb.demo

Change Game Class to your preferred game class name , I am using VersionPB

Keep destination as the directory where you want libGDX to create your projects

Add Android SDK root path in front of Android SDK , for me android sdk was downloaded in C:\Users\<USER>\android-sdks

Keep All sub projects checked i.e. Desktop,Android,Ios  and HTML as we are going to create this demo for all these platforms …

uncheck all the Extensions

Click on Advanced and check Eclipse and click save .

Your Screen should look like below screenshot :

libGDX_demo

 

libGDXAdvanced

 

Click generate and the setup app will take a sometime to complete downloading and configuring your project. For me the very first time it took 50 minutes so please be patient and in case you get messages like Build Failed , try again with overwrite option .

 

it may also ask you about updating your android build tools or using a particular build tool for android once you click yes android manager will be opened and you can start installing the required tools , click yes in case you have latest android build tool available

UseAndroidBuildTool

On Successful setup , you should see below screenshot :

libGDXSuccess

 

Once we see this , We are done and now we will go to next step i.e. to run project via Eclipse .



 

  • Importing Projects in Eclipse
  • Open Eclipse in a workspace of your choice , make sure its not the same directory as the one which you used for libGDX project .

Execute following steps in Eclipse :

  • File –> Import

EclipseImport

  • Select Gradle — > Gradle Project — Next — Next

EclipseGradleImport

  • Add Project root directory i.e. project Destination which was using while using libGDX Project Setup . For my case it was D:\Paarth\Google_Drive\Google Drive\Codes\libgdx\versionPBDemo

EclipseGradleProjectImport

 

  • Click finish and it will synchronize  with gradle root project using following window , it should take 1 to 2 minutes to finish this .

SynchronizingGradleRoot

 

  • Once this is done open Package Explorer of Eclipse and you should see following projects there :

versionPBDemo
versionpb-android
versionpb-core
versionpb-desktop
versionpb-html
versionpb-ios

Wow Importing Projects in Eclipse is done . next Step is to execute the demo project for Windows …



  • Executing demo project for Windows
  • For my case I need to run versionpb-desktop . Right click versionpb-desktop in Eclipse , Select Run As and select Java Application

Desktop_JavaApplication

  • You will see some options , select DesktopLauncher as per below screenshot and click ok

DesktopLauncher

  •  Doing that Desktop App should open . In my case it was like below screenshot

DemoDesktopApp



 

  • Executing demo project for Android

 

  • For my case I need to run versionpb-android .Right click versionpb-android in Eclipse , Select Run As and select Android Application

Android_JavaApplication

 

  • Doing that Android device chooser will open up as screen below

AndroidDeviceChooser

The Upper Section is for a running android device i.e. a real android device connected to your laptop/machine with USB and with USB debugging enabled . Lets enable developer options in the mobile phone .

I am using Samsung Galaxy S3 whose developer options are found in Settings — > More . by default developer options are hidden . To know how to un hide it , read this blog .

Once developer options are visible , turn USB debugging on and connect device with your laptop/machine . You will see a message on my mobile stating Allow USB debugging ?

Click OK and you will see your device as in Online State in Android device Chooser . See screenshot below :

MobileDeviceOnline

 

Select this device in Android device chooser and click OK . Doing that Demo app will open up in your mobile device .

You may get an error stating unfortunately the android has stopped i.e. your android app may crash  as It  happened with me as well .

To fix this  :

  1. right click your android project
  2. Select properties
  3. Select Java Build path
  4. it will be something like below :
  5. AndroidCrashFix
  6. Check all the unchecked values and click OK .
  7. Remove your device from your laptop USB .
  8. Clean and build your project by Clicking Clean as below :

CleanProject

  • Add your device back to USB with machine . Allow USB Debugging and run the android project again .
  • This time you will see demo app running on your mobile .


 

To run this on a virtual device you need to create a virtual device .Read following to know How to create a virtual device .

Once your Android Virtual Device i.e. AVD is seen in the list of AVDs  , Select the AVD and click OK and you will see demo project running on your AVD as per screenshot below :

 

AVDdemo

 



 

  • Executing demo project for HTML5

 

  • For my case I need to run versionpb-html . Right click on versionpb-html and select Run As –>  Run Configurations …

htmlRunConfigurations

 

  • Once you click this you will see Configuration Screen open , Select Gradle project and click on new from top menu to create a new Gradle configuration . Lets Configure Gradle task configuration .
  • Give it a name as superDev
  • Gradle tasks should be gradlew.bat
  • Working Directory should be your project Directory which we used when we setup the project for libGDX . You should see a screen like below

GradleTaskConfiguration

 

  • Once this is done open Gradle argument tab and write html:superDev there . Gradle argument screen should look like as below :

gradleArguments

 

  • Once done click run and you should see screen like below :

GradleSuccess

 

  • Open the console window and wait for following :
  • The code server is ready.
    Next, visit: http://localhost:9876/

 

CodeServerReady

 

  • Open this url http://localhost:9876/ in any web browser to see GWT Code Server  as below

 

GWTCodeServer

 

  • To see your html App open URL : http://localhost:8080/html/ . It should be as below

 

htmlApp

Full Tutorial Seris on libGDX

One Comment:

  1. Pingback: Step by Step Tutorial on libGDX | anupuru

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 89 = 94